<!DOCTYPE html>
<!-- saved from url=(0061)https://blog.csdn.net/twj1248445531/article/details/111032255 -->
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style>.login-box{position: fixed;display: none;left: 50%;top: 50%;z-index: 10000;-webkit-transform: translate(-50%, -50%);-ms-transform: translate(-50%, -50%);-o-transform: translate(-50%, -50%);-moz-transform: translate(-50%, -50%);transform: translate(-50%, -50%);background-color: #fff;}.login-mark{position: fixed;top: 0;left: 0;z-index: 9999;background-color: rgba(0, 0, 0, 0.5);width: 100%;height: 100%;display: none;}</style>
    <link rel="canonical" href="https://blog.csdn.net/twj1248445531/article/details/111032255">
    
    <meta name="renderer" content="webkit">
    <meta name="force-rendering" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="report" content="{&quot;pid&quot;: &quot;blog&quot;, &quot;spm&quot;:&quot;1001.2101&quot;}">
    <meta name="referrer" content="always">
    <meta http-equiv="Cache-Control" content="no-siteapp"><link rel="alternate" media="handheld" href="https://blog.csdn.net/twj1248445531/article/details/111032255#">
    <meta name="shenma-site-verification" content="5a59773ab8077d4a62bf469ab966a63b_1497598848">
    <meta name="applicable-device" content="pc">
    <link href="https://g.csdnimg.cn/static/logo/favicon32.ico" rel="shortcut icon" type="image/x-icon">
    <title>(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客</title>
    <script type="text/javascript" async="" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/auto_dup"></script><script type="text/javascript" charset="utf-8" async="" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/apiaccept"></script><script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/push.js"></script><script type="text/javascript" async="" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/saved_resource(1)"></script><script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/hm.js"></script><script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/push(1).js" id="ttzz"></script><script>
      (function(){ 
        var el = document.createElement("script"); 
        el.src = "https://s3a.pstatp.com/toutiao/push.js?1abfa13dfe74d72d41d83c86d240de427e7caοnerrοr='setTimeoutc50c51ead53b2e79d40c7952a23ed7716d05b4a0f683a653eab3e214672511de2457e74e99286eb2c33f4428830";
        el.id = "ttzz"; 
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(el, s);
      })(window)
    </script>
        <meta name="keywords" content="Java实现简易UDP客户端、服务器端通信程序">
        <meta name="csdn-baidu-search" content="{&quot;autorun&quot;:true,&quot;install&quot;:true,&quot;keyword&quot;:&quot;Java实现简易UDP客户端、服务器端通信程序&quot;}">
    <meta name="description" content="本学期计算机网络课程要求完成一个TCP和一个UDP的通信程序，我完成了功能的简单实现。我在上一篇博客已经讲了TCP的具体实现，接下来讲一讲UDP程序的实现。目录效果展示一、项目结构二、完整代码1.UDPClient2.UDPServer3.UDPFrame4.UDPSend5.UDPReceive6.ReminderTextAdapter（参考别人的，非原创）总结效果展示以下是具体实现过程：一、项目结构下面说说每个类的具体作用：UDPClient：UDP客户端的核心代码部分；U">
    <script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/blog.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/detail_enter-98a9ff6ab5.min.css">
        <link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/skin-sea-d3a08c2048.min.css">
    <script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var isCorporate = false;//注释删除enterprise
        var username =  "twj1248445531";
        var skinImg = "white";
        var blog_address = "https://blog.csdn.net/twj1248445531";
        var currentUserName = "hwf453";
        var isOwner = false;
        var loginUrl = "http://passport.csdn.net/account/login?from=https://blog.csdn.net/twj1248445531/article/details/111032255";
        var blogUrl = "https://blog.csdn.net/";
        var avatar = "https://profile.csdnimg.cn/3/8/E/3_twj1248445531";
        var articleTitle = "Java实现简易UDP客户端、服务器端通信程序";
        var articleDesc = "本学期计算机网络课程要求完成一个TCP和一个UDP的通信程序，我完成了功能的简单实现。我在上一篇博客已经讲了TCP的具体实现，接下来讲一讲UDP程序的实现。目录效果展示一、项目结构二、完整代码1.UDPClient2.UDPServer3.UDPFrame4.UDPSend5.UDPReceive6.ReminderTextAdapter（参考别人的，非原创）总结效果展示以下是具体实现过程：一、项目结构下面说说每个类的具体作用：UDPClient：UDP客户端的核心代码部分；U";
        var articleTitles = "Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客";
        var nickName = "主旋律T";
        var articleDetailUrl = "https://blog.csdn.net/twj1248445531/article/details/111032255";
        if(window.location.host.split('.').length == 3) {
            blog_address = blogUrl + username;
        }
        var skinStatus = "White";
        var blogStaticHost = "https://csdnimg.cn/release/blogv2/"
    </script>
    <script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/saved_resource(2)" type="text/javascript"></script>
    <script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/report.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/sandalstrap.min.css">
    <style>
        .MathJax, .MathJax_Message, .MathJax_Preview{
            display: none
        }
    </style>
    <script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/ds.js"></script>
<link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/csdn-toolbar-default.css"><script type="text/javascript" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/csdn-notification.js"></script><script type="text/javascript" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/baidu_opensug-1.0.1.js"></script><link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/user-login.css"><link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/collection-box.css"><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><style type="text/css"></style><link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/user-tooltip.css"><link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/user-medal.css"><style type="text/css">pre{position: relative}pre:hover .hljs-button{display: block}.hljs-button{display: none;position: absolute;right: 4px;top: 4px;font-size: 12px;color: #4d4d4d;background-color: white;padding: 2px 8px;margin: 8px;border-radius: 4px;cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.05);}.hljs-button:after{content: attr(data-title)}code .hljs-button{margin: 2px 8px;}</style><style type="text/css">.hljs-ln{border-collapse:collapse}            .hljs-ln td{padding:0}            .hljs-ln-n{text-align: right;padding-right: 8px;}            .hljs-ln-n:before{content:attr(data-line-number)}</style><link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/side-toolbar.css"><link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/csdn-footer.css"><link rel="stylesheet" type="text/css" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/shop-window.css"><style type="text/css">.MathJax_Hover_Frame {border-radius: .25em; -webkit-border-radius: .25em; -moz-border-radius: .25em; -khtml-border-radius: .25em; box-shadow: 0px 0px 15px #83A; -webkit-box-shadow: 0px 0px 15px #83A; -moz-box-shadow: 0px 0px 15px #83A; -khtml-box-shadow: 0px 0px 15px #83A; border: 1px solid #A6D ! important; display: inline-block; position: absolute}
.MathJax_Menu_Button .MathJax_Hover_Arrow {position: absolute; cursor: pointer; display: inline-block; border: 2px solid #AAA; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -khtml-border-radius: 4px; font-family: 'Courier New',Courier; font-size: 9px; color: #F0F0F0}
.MathJax_Menu_Button .MathJax_Hover_Arrow span {display: block; background-color: #AAA; border: 1px solid; border-radius: 3px; line-height: 0; padding: 4px}
.MathJax_Hover_Arrow:hover {color: white!important; border: 2px solid #CCC!important}
.MathJax_Hover_Arrow:hover span {background-color: #CCC!important}
</style><style type="text/css">#MathJax_About {position: fixed; left: 50%; width: auto; text-align: center; border: 3px outset; padding: 1em 2em; background-color: #DDDDDD; color: black; cursor: default; font-family: message-box; font-size: 120%; font-style: normal; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -khtml-border-radius: 15px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_About.MathJax_MousePost {outline: none}
.MathJax_Menu {position: absolute; background-color: white; color: black; width: auto; padding: 5px 0px; border: 1px solid #CCCCCC; margin: 0; cursor: default; font: menu; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; -khtml-border-radius: 5px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_MenuItem {padding: 1px 2em; background: transparent}
.MathJax_MenuArrow {position: absolute; right: .5em; padding-top: .25em; color: #666666; font-size: .75em}
.MathJax_MenuActive .MathJax_MenuArrow {color: white}
.MathJax_MenuArrow.RTL {left: .5em; right: auto}
.MathJax_MenuCheck {position: absolute; left: .7em}
.MathJax_MenuCheck.RTL {right: .7em; left: auto}
.MathJax_MenuRadioCheck {position: absolute; left: .7em}
.MathJax_MenuRadioCheck.RTL {right: .7em; left: auto}
.MathJax_MenuLabel {padding: 1px 2em 3px 1.33em; font-style: italic}
.MathJax_MenuRule {border-top: 1px solid #DDDDDD; margin: 4px 3px}
.MathJax_MenuDisabled {color: GrayText}
.MathJax_MenuActive {background-color: #606872; color: white}
.MathJax_MenuDisabled:focus, .MathJax_MenuLabel:focus {background-color: #E8E8E8}
.MathJax_ContextMenu:focus {outline: none}
.MathJax_ContextMenu .MathJax_MenuItem:focus {outline: none}
#MathJax_AboutClose {top: .2em; right: .2em}
.MathJax_Menu .MathJax_MenuClose {top: -10px; left: -10px}
.MathJax_MenuClose {position: absolute; cursor: pointer; display: inline-block; border: 2px solid #AAA; border-radius: 18px; -webkit-border-radius: 18px; -moz-border-radius: 18px; -khtml-border-radius: 18px; font-family: 'Courier New',Courier; font-size: 24px; color: #F0F0F0}
.MathJax_MenuClose span {display: block; background-color: #AAA; border: 1.5px solid; border-radius: 18px; -webkit-border-radius: 18px; -moz-border-radius: 18px; -khtml-border-radius: 18px; line-height: 0; padding: 8px 0 6px}
.MathJax_MenuClose:hover {color: white!important; border: 2px solid #CCC!important}
.MathJax_MenuClose:hover span {background-color: #CCC!important}
.MathJax_MenuClose:hover:focus {outline: none}
</style><style type="text/css">.MathJax_Preview .MJXf-math {color: inherit!important}
</style><style type="text/css">.MJX_Assistive_MathML {position: absolute!important; top: 0; left: 0; clip: rect(1px, 1px, 1px, 1px); padding: 1px 0 0 0!important; border: 0!important; height: 1px!important; width: 1px!important; overflow: hidden!important; display: block!important; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none}
.MJX_Assistive_MathML.MJX_Assistive_MathML_Block {width: 100%!important}
</style><style type="text/css">#MathJax_Zoom {position: absolute; background-color: #F0F0F0; overflow: auto; display: block; z-index: 301; padding: .5em; border: 1px solid black; margin: 0; font-weight: normal; font-style: normal; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; box-shadow: 5px 5px 15px #AAAAAA; -webkit-box-shadow: 5px 5px 15px #AAAAAA; -moz-box-shadow: 5px 5px 15px #AAAAAA; -khtml-box-shadow: 5px 5px 15px #AAAAAA; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_ZoomOverlay {position: absolute; left: 0; top: 0; z-index: 300; display: inline-block; width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
#MathJax_ZoomFrame {position: relative; display: inline-block; height: 0; width: 0}
#MathJax_ZoomEventTrap {position: absolute; left: 0; top: 0; z-index: 302; display: inline-block; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
</style><style type="text/css">.MathJax_Preview {color: #888}
#MathJax_Message {position: fixed; left: 1em; bottom: 1.5em; background-color: #E6E6E6; border: 1px solid #959595; margin: 0px; padding: 2px 8px; z-index: 102; color: black; font-size: 80%; width: auto; white-space: nowrap}
#MathJax_MSIE_Frame {position: absolute; top: 0; left: 0; width: 0px; z-index: 101; border: 0px; margin: 0px; padding: 0px}
.MathJax_Error {color: #CC0000; font-style: italic}
</style><style type="text/css">.MJXp-script {font-size: .8em}
.MJXp-right {-webkit-transform-origin: right; -moz-transform-origin: right; -ms-transform-origin: right; -o-transform-origin: right; transform-origin: right}
.MJXp-bold {font-weight: bold}
.MJXp-italic {font-style: italic}
.MJXp-scr {font-family: MathJax_Script,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-frak {font-family: MathJax_Fraktur,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-sf {font-family: MathJax_SansSerif,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-cal {font-family: MathJax_Caligraphic,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-mono {font-family: MathJax_Typewriter,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-largeop {font-size: 150%}
.MJXp-largeop.MJXp-int {vertical-align: -.2em}
.MJXp-math {display: inline-block; line-height: 1.2; text-indent: 0; font-family: 'Times New Roman',Times,STIXGeneral,serif; white-space: nowrap; border-collapse: collapse}
.MJXp-display {display: block; text-align: center; margin: 1em 0}
.MJXp-math span {display: inline-block}
.MJXp-box {display: block!important; text-align: center}
.MJXp-box:after {content: " "}
.MJXp-rule {display: block!important; margin-top: .1em}
.MJXp-char {display: block!important}
.MJXp-mo {margin: 0 .15em}
.MJXp-mfrac {margin: 0 .125em; vertical-align: .25em}
.MJXp-denom {display: inline-table!important; width: 100%}
.MJXp-denom > * {display: table-row!important}
.MJXp-surd {vertical-align: top}
.MJXp-surd > * {display: block!important}
.MJXp-script-box > *  {display: table!important; height: 50%}
.MJXp-script-box > * > * {display: table-cell!important; vertical-align: top}
.MJXp-script-box > *:last-child > * {vertical-align: bottom}
.MJXp-script-box > * > * > * {display: block!important}
.MJXp-mphantom {visibility: hidden}
.MJXp-munderover {display: inline-table!important}
.MJXp-over {display: inline-block!important; text-align: center}
.MJXp-over > * {display: block!important}
.MJXp-munderover > * {display: table-row!important}
.MJXp-mtable {vertical-align: .25em; margin: 0 .125em}
.MJXp-mtable > * {display: inline-table!important; vertical-align: middle}
.MJXp-mtr {display: table-row!important}
.MJXp-mtd {display: table-cell!important; text-align: center; padding: .5em 0 0 .5em}
.MJXp-mtr > .MJXp-mtd:first-child {padding-left: 0}
.MJXp-mtr:first-child > .MJXp-mtd {padding-top: 0}
.MJXp-mlabeledtr {display: table-row!important}
.MJXp-mlabeledtr > .MJXp-mtd:first-child {padding-left: 0}
.MJXp-mlabeledtr:first-child > .MJXp-mtd {padding-top: 0}
.MJXp-merror {background-color: #FFFF88; color: #CC0000; border: 1px solid #CC0000; padding: 1px 3px; font-style: normal; font-size: 90%}
.MJXp-scale0 {-webkit-transform: scaleX(.0); -moz-transform: scaleX(.0); -ms-transform: scaleX(.0); -o-transform: scaleX(.0); transform: scaleX(.0)}
.MJXp-scale1 {-webkit-transform: scaleX(.1); -moz-transform: scaleX(.1); -ms-transform: scaleX(.1); -o-transform: scaleX(.1); transform: scaleX(.1)}
.MJXp-scale2 {-webkit-transform: scaleX(.2); -moz-transform: scaleX(.2); -ms-transform: scaleX(.2); -o-transform: scaleX(.2); transform: scaleX(.2)}
.MJXp-scale3 {-webkit-transform: scaleX(.3); -moz-transform: scaleX(.3); -ms-transform: scaleX(.3); -o-transform: scaleX(.3); transform: scaleX(.3)}
.MJXp-scale4 {-webkit-transform: scaleX(.4); -moz-transform: scaleX(.4); -ms-transform: scaleX(.4); -o-transform: scaleX(.4); transform: scaleX(.4)}
.MJXp-scale5 {-webkit-transform: scaleX(.5); -moz-transform: scaleX(.5); -ms-transform: scaleX(.5); -o-transform: scaleX(.5); transform: scaleX(.5)}
.MJXp-scale6 {-webkit-transform: scaleX(.6); -moz-transform: scaleX(.6); -ms-transform: scaleX(.6); -o-transform: scaleX(.6); transform: scaleX(.6)}
.MJXp-scale7 {-webkit-transform: scaleX(.7); -moz-transform: scaleX(.7); -ms-transform: scaleX(.7); -o-transform: scaleX(.7); transform: scaleX(.7)}
.MJXp-scale8 {-webkit-transform: scaleX(.8); -moz-transform: scaleX(.8); -ms-transform: scaleX(.8); -o-transform: scaleX(.8); transform: scaleX(.8)}
.MJXp-scale9 {-webkit-transform: scaleX(.9); -moz-transform: scaleX(.9); -ms-transform: scaleX(.9); -o-transform: scaleX(.9); transform: scaleX(.9)}
.MathJax_PHTML .noError {vertical-align: ; font-size: 90%; text-align: left; color: black; padding: 1px 3px; border: 1px solid}
</style></head>
<body class="nodata " style="overflow: auto;"><div id="MathJax_Message" style="display: none;"></div><div id="csdn-toolbar" style="position: relative; top: 0px; left: 0px; width: 100%;">
                    <div class="toolbar-inside">
                      <div class="toolbar-container">
                        <div class="toolbar-container-left">
                          <div class="toolbar-logo toolbar-subMenu-box csdn-toolbar-fl"><a data-report-click="{&quot;spm&quot;:&quot;3001.4476&quot;}" data-report-query="spm=3001.4476" href="https://www.csdn.net/"><img title="CSDN首页" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201124032511.png"></a>
                    <div class="toolbar-subMenu">
                    <img width="96" height="96" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201120101655.png">
                  </div></div>
                          <ul class="toolbar-menus csdn-toolbar-fl" style="width: auto;"><li class="">
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://www.csdn.net/&quot;,&quot;spm&quot;:&quot;3001.5359&quot;}" data-report-query="spm=3001.5359" href="https://www.csdn.net/">
                                  首页
                                  
                                  
                                </a>
                                
                                
                              </li><li class="active ">
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/&quot;,&quot;spm&quot;:&quot;3001.4477&quot;}" data-report-query="spm=3001.4477" href="https://blog.csdn.net/">
                                  博客
                                  
                                  
                                </a>
                                
                                
                              </li><li class="">
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://edu.csdn.net/&quot;,&quot;spm&quot;:&quot;3001.4482&quot;}" data-report-query="spm=3001.4482" href="https://edu.csdn.net/">
                                  专栏课程
                                  
                                  
                                </a>
                                
                                
                              </li><li class="">
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/&quot;,&quot;spm&quot;:&quot;3001.4483&quot;}" data-report-query="spm=3001.4483" href="https://download.csdn.net/">
                                  下载
                                  
                                  
                                </a>
                                
                                
                              </li><li class="">
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://ask.csdn.net/&quot;,&quot;spm&quot;:&quot;3001.4492&quot;}" data-report-query="spm=3001.4492" href="https://ask.csdn.net/">
                                  问答
                                  
                                  
                                </a>
                                
                                
                              </li><li class="">
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://www.csdn.net/c/&quot;,&quot;spm&quot;:&quot;3001.6068&quot;}" data-report-query="spm=3001.6068" href="https://www.csdn.net/c/">
                                  社区
                                  
                                  
                                </a>
                                
                                
                              </li><li class="toolbar-subMenu-box toolbar-subSlider-box">
                                <a href="javascript:void(0);">
                                  更多
                                  
                                  <i class="toolbar-subMenu-arrowHead"></i>
                                </a>
                                <div class="toolbar-subMenu">
                                    <a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://codechina.csdn.net/?utm_source=csdn_toolbar&quot;,&quot;spm&quot;:&quot;3001.4493&quot;}" data-report-query="spm=3001.4493" target="_blank" href="https://codechina.csdn.net/?utm_source=csdn_toolbar">代码</a><a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://codechina.csdn.net/?utm_source=csdn_toolbar&quot;,&quot;spm&quot;:&quot;3001.5342&quot;}" data-report-query="spm=3001.5342" target="_blank" href="https://live.csdn.net/?utm_source=csdn_toolbar">直播</a><a data-report-click="{&quot;spm&quot;:&quot;3001.6135&quot;,&quot;dist&quot;:&quot;https://t.csdnimg.cn/OSqE&quot;}" data-report-query="spm=3001.6135" target="_blank" href="https://t.csdnimg.cn/OSqE">Chrome 插件</a><a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://ac.csdn.net/&quot;,&quot;spm&quot;:&quot;3001.5716&quot;}" data-report-query="spm=3001.5716" target="_blank" href="https://ac.csdn.net/">能力认证</a>
                                  </div>
                                <div class="toolbar-subSlider">
                                  <div class="toolbar-subSlider-more" style="margin-top: -96px; transition: all 0.8s ease 0s;">
                                    <a target="_blank" href="javascript:void(0);">代码</a><a target="_blank" href="javascript:void(0);">直播</a>
                                    <a target="_blank" href="javascript:void(0);">代码</a></div>
                                  </div>
                              </li></ul>
                        </div>
                        <div class="toolbar-container-middle">
                          <div class="toolbar-search onlySearch"><div class="toolbar-search-container">
                    <input id="toolbar-search-input" autocomplete="off" type="text" value="" placeholder="socket">
                    <button id="toolbar-search-button"></button>
                    <input type="password" autocomplete="new-password" readonly="" disabled="true" style="display: none; position:absolute;left:-9999999px;width:0;height:0;">
                  </div></div>
                        </div>
                        <div class="toolbar-container-right">
                          <div class="toolbar-btns onlyUser"><div class="toolbar-btn toolbar-btn-login csdn-toolbar-fl toolbar-subMenu-box">
                      <a class="hasAvatar" data-report-click="{&quot;spm&quot;: &quot;3001.5343&quot;}" data-report-query="spm=3001.5343" href="https://blog.csdn.net/hwf453"><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/2_hwf453"></a>
                      <div id="csdn-toolbar-profile" class="csdn-toolbar-plugin">
            <div class="csdn-profile-top">
              <a class="csdn-profile-avatar" data-report-click="{&quot;spm&quot;: &quot;3001.5343&quot;}" data-report-query="spm=3001.5343" href="https://blog.csdn.net/hwf453"><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/0_hwf453"></a>
              <p class="csdn-profile-nickName">hwf453</p>
              <a data-report-click="{&quot;spm&quot;: &quot;3001.5344&quot;}" data-report-query="spm=3001.5344" href="https://mall.csdn.net/vip" class="csdn-profile-no-vip"></a>
            </div>
            <div class="csdn-profile-mid">
              <a data-report-click="{&quot;spm&quot;: &quot;3001.5347&quot;}" data-report-query="spm=3001.5347" href="https://blog.csdn.net/hwf453?type=sub&amp;subType=fans"><i class="csdn-profile-fansCount">3</i>粉丝</a>
              <a data-report-click="{&quot;spm&quot;: &quot;3001.5348&quot;}" data-report-query="spm=3001.5348" href="https://blog.csdn.net/hwf453?type=sub"><i class="csdn-profile-followCount">--</i>关注</a>
              <a data-report-click="{&quot;spm&quot;: &quot;3001.5349&quot;}" data-report-query="spm=3001.5349" href="https://blog.csdn.net/hwf453"><i class="csdn-profile-likeCount">--</i>获赞</a>
            </div>
            <div class="csdn-profile-bottom">
              <ul class="csdn-border-bottom">
                <li class=""><a href="https://i.csdn.net/#/user-center/profile" data-report-click="{&quot;dest&quot;:&quot;https://i.csdn.net/#/user-center/profile&quot;,&quot;spm&quot;:&quot;3001.5111&quot;}" data-report-query="spm=3001.5111"><i class="csdn-profile-icon csdn-profile-icon-person"></i>个人中心</a></li><li class=""><a href="https://mp.csdn.net/mp_blog/manage/article?spm=1011.2124.3001.5298" data-report-click="{&quot;dest&quot;:&quot;https://mp.csdn.net/mp_blog/manage/article?spm=1011.2124.3001.5298&quot;,&quot;spm&quot;:&quot;3001.5448&quot;}" data-report-query="spm=3001.5448"><i class="csdn-profile-icon csdn-profile-icon-pages"></i>内容管理</a></li><li class=""><a href="https://edu.csdn.net/" data-report-click="{&quot;dest&quot;:&quot;https://edu.csdn.net/&quot;,&quot;spm&quot;:&quot;3001.5350&quot;}" data-report-query="spm=3001.5350"><i class="csdn-profile-icon csdn-profile-icon-study"></i>学习平台</a></li><li class=""><a href="https://mall.csdn.net/myorder" data-report-click="{&quot;dest&quot;:&quot;https://mall.csdn.net/myorder&quot;,&quot;spm&quot;:&quot;3001.5137&quot;}" data-report-query="spm=3001.5137"><i class="csdn-profile-icon csdn-profile-icon-order"></i>我的订单</a></li><li class="pb-8 csdn-border-bottom"><a href="https://i.csdn.net/#/wallet/index" data-report-click="{&quot;dest&quot;:&quot;https://i.csdn.net/#/wallet/index&quot;,&quot;spm&quot;:&quot;3001.5136&quot;}" data-report-query="spm=3001.5136"><i class="csdn-profile-icon csdn-profile-icon-wallet"></i>我的钱包</a></li><li class="pt-8 pb-8 csdn-border-bottom"><a href="https://i.csdn.net/#/uc/reward" data-report-click="{&quot;dest&quot;:&quot;https://i.csdn.net/#/uc/reward&quot;,&quot;spm&quot;:&quot;3001.5351&quot;}" data-report-query="spm=3001.5351"><i class="csdn-profile-icon csdn-profile-icon-draw"></i>签到抽奖</a></li><li class="pt-8 csdn-profile-logout"><a href="javascript:;" data-report-click="{&quot;spm&quot;:&quot;3001.5139&quot;}" data-report-query="spm=3001.5139"><i class="csdn-profile-icon csdn-profile-icon-logout"></i>退出</a></li>
              </ul>
            </div>
          </div></div>
                    <div class="toolbar-btn toolbar-btn-vip csdn-toolbar-fl">
                      <a data-report-click="{&quot;mod&quot;:&quot;popu_336&quot;,&quot;dest&quot;:&quot;https://mall.csdn.net/vip&quot;,&quot;spm&quot;:&quot;3001.4496&quot;}" data-report-query="spm=3001.4496" href="https://mall.csdn.net/vip">会员中心 </a>
                    <div id="csdn-plugin-vip">
                        <div class="csdn-plugin-vip-header">
                            会员特权
                        </div>
                        <div class="csdn-plugin-vip-body">
                            <a href="https://download.csdn.net/?utm_source=vip_xz_862637798_yy"><i class="csdn-plugin-vip-icon csdn-plugin-vip-icon-download"></i><br>资源下载</a>
                            <a href="https://edu.csdn.net/course?channelType=3&amp;utm_source=vip_jpk_862637798_yy"><i class="csdn-plugin-vip-icon csdn-plugin-vip-icon-class"></i><br>千节精品课</a>
                            <a href="https://book.csdn.net/?utm_source=vip_dzs_862637798_yy"><i class="csdn-plugin-vip-icon csdn-plugin-vip-icon-book"></i><br>千本电子书</a>
                            <a href="https://so.csdn.net/so/search?q=&amp;t=vip&amp;s=0&amp;pnt=-1&amp;ct=100&amp;utm_source=vip_jswz_862637798_yy"><i class="csdn-plugin-vip-icon csdn-plugin-vip-icon-pages"></i><br>VIP技术文章</a>
                        </div>
                        <div class="csdn-plugin-vip-footer">
                            <a data-report-click="{&quot;spm&quot;: &quot;3001.5400&quot;}" data-report-query="spm=3001.5400" class="csdn-plugin-vip-footer-btn" href="https://mall.csdn.net/vip">
                              开通会员
                            </a>
                            <a data-report-click="{&quot;spm&quot;: &quot;3001.5401&quot;}" data-report-query="spm=3001.5401" class="csdn-plugin-vip-footer-link" href="https://www.csdn.net/vip">
                              查看完整会员权益<i></i>
                            </a>
                        </div>
                    </div></div>
                    <div class="toolbar-btn toolbar-btn-collect csdn-toolbar-fl">
                      <a data-report-click="{&quot;spm&quot;:&quot;3001.4506&quot;}" data-report-query="spm=3001.4506" href="https://i.csdn.net/#/user-center/collection-list?type=1">收藏</a>
                    
          <div id="csdn-toolbar-collection" class="csdn-toolbar-plugin" style="display: none;">
            <div class="toolbar-collection-left csdn-toolbar-scroll-box">
              <ul>
          <li class="collection-folder-active">
            <div class="toolbar-collection-folder-name">默认收藏夹</div>
            <div class="toolbar-collection-folder-count">1</div>
          </li>
        </ul>
            </div>
            <div class="toolbar-collection-right">
              <ul class="csdn-toolbar-scroll-box">
          <li>
            <a href="https://download.csdn.net/download/u010411826/8363605" target="_blank">
              <span class="toolbar-collection-type">资源</span>
              <span class="toolbar-collection-title">AChartEngineDemo</span>
            </a>
          </li>
        </ul>
            </div>
            <div class="csdn-toolbar-plugin-triangle"></div>
          </div>
        </div>
                     <div class="toolbar-btn csdn-toolbar-fl"><a data-report-click="{&quot;spm&quot;:&quot;3001.4507&quot;}" data-report-query="spm=3001.4507" href="https://blog.csdn.net/nav/watchers">动态</a></div>
                    <div class="toolbar-btn toolbar-btn-msg csdn-toolbar-fl">
                      <div class="toolbar-subMenu-box">
                        <a data-report-click="{&quot;spm&quot;:&quot;3001.4508&quot;}" data-report-query="spm=3001.4508" id="toolbar-remind" href="https://i.csdn.net/#/msg/index"><span class="pos-rel">消息<i class="toolbar-msg-count"></i></span></a>
                      <div class="toolbar-subMenu">
                    <a id="toolbar-announcement" href="https://blog.csdn.net/blogdevteam/article/details/112280974?utm_source=gonggao_0107"><span class="pos-rel">公告</span></a>
                    <a data-type="comment" href="https://i.csdn.net/#/msg/index"><span class="pos-rel">评论</span></a>
                                      <a data-type="attention" href="https://i.csdn.net/#/msg/attention"><span class="pos-rel">关注</span></a>         
                                      <a data-type="like" href="https://i.csdn.net/#/msg/like"><span class="pos-rel">点赞</span></a>
                                      <a data-type="chat" href="https://im.csdn.net/im/main.html"><span class="pos-rel">私信<i></i></span></a>
                                      <a data-type="notice" href="https://i.csdn.net/#/msg/notice"><span class="pos-rel">系统通知<i></i></span></a>
                                      <a href="https://i.csdn.net/#/msg/setting">消息设置</a>     
                  </div></div>
                      <div class="toolbar-msg-box"></div>
                    </div>
                    <div class="toolbar-btn toolbar-btn-write csdn-toolbar-fl toolbar-subMenu-box">
                      <a data-report-click="{&quot;spm&quot;:&quot;3001.4503&quot;}" data-report-query="spm=3001.4503" href="https://mp.csdn.net/"><i></i>创作中心</a>
                    </div></div>
                        </div>
                      </div>
                    </div>
                  </div>
        <script>
            var toolbarSearchExt = '{"landingWord":[],"queryWord":"","tag":["java","socket","计算机网络","udp","网络通信"],"title":"Java实现简易UDP客户端、服务器端通信程序"}';
        </script>
    <script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/csdn-toolbar.js" type="text/javascript"></script>
    <script>
    (function(){
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        }
        else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
    </script>
<link rel="stylesheet" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/blog_code-01256533b5.min.css">
<link rel="stylesheet" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/chart-3456820cac.css">
<div class="main_father clearfix d-flex justify-content-center" style="height:100%;"> 
    <div class="container clearfix" id="mainBox">
        <main>
<script type="text/javascript">
    var blogSensitiveWords = "";
    function getQueryString(name) {   
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象  
      var r = window.location.search.substr(1).match(reg);  //匹配目标参数
      if( r != null ) return decodeURIComponent( r[2] ); return '';   
    }
    function stripscript(s){ 
      var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？%]") 
      var rs = ""; 
      for (var i = 0; i < s.length; i++) { 
        rs = rs+s.substr(i, 1).replace(pattern, ''); 
      } 
      return rs; 
    }
    var blogHotWords = stripscript(getQueryString('utm_term')).length > 1 ? stripscript(getQueryString('utm_term')) : ''
</script>
<div class="blog-content-box">
    <div class="article-header-box">
        <div class="article-header">
            <div class="article-title-box">
                <h1 class="title-article" id="articleContentId">Java实现简易UDP客户端、服务器端通信程序</h1>
            </div>
            <div class="article-info-box">
                <div class="article-bar-top">
                    <img class="article-type-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/original.png" alt="">
                    <div class="bar-content">
                    <a class="follow-nickName " href="https://blog.csdn.net/twj1248445531" target="_blank" rel="noopener">主旋律T</a>
                    <span class="time">2020-12-11 16:00:00</span>
                    <img class="article-read-img article-heard-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/articleReadEyes.png" alt="">
                    <span class="read-count">394</span>
                    <a id="blog_detail_zk_collection" class="un-collection" data-report-click="{&quot;mod&quot;:&quot;popu_823&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4232&quot;,&quot;ab&quot;:&quot;new&quot;}">
                        <img class="article-collect-img article-heard-img un-collect-status isdefault" style="display:inline-block" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarCollect.png" alt="">
                        <img class="article-collect-img article-heard-img collect-status isactive" style="display:none" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarCollectionActive.png" alt="">
                        <span class="name">收藏</span>
                        <span class="get-collection">
                            5
                        </span>
                    </a>
                    </div>
                </div>
                <div class="blog-tags-box">
                    <div class="tags-box artic-tag-box">
                            <span class="label">分类专栏：</span>
                                <a class="tag-link" href="https://blog.csdn.net/twj1248445531/category_10647981.html" target="_blank" rel="noopener">计算机网络小项目</a>
                            <span class="label">文章标签：</span>
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_626&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4223&quot;,&quot;strategy&quot;:&quot;java&quot;,&quot;ab&quot;:&quot;new&quot;}" class="tag-link" href="https://www.csdn.net/tags/NtTaIg5sMzYyLWJsb2cO0O0O.html" target="_blank" rel="noopener">java</a>
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_626&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4223&quot;,&quot;strategy&quot;:&quot;socket&quot;,&quot;ab&quot;:&quot;new&quot;}" class="tag-link" href="https://www.csdn.net/tags/MtTaEg0sMDg5OTgtYmxvZwO0O0OO0O0O.html" target="_blank" rel="noopener">socket</a>
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_626&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4223&quot;,&quot;strategy&quot;:&quot;计算机网络&quot;,&quot;ab&quot;:&quot;new&quot;}" class="tag-link" href="https://www.csdn.net/tags/MtTacg1sNjA5My1ibG9n.html" target="_blank" rel="noopener">计算机网络</a>
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_626&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4223&quot;,&quot;strategy&quot;:&quot;udp&quot;,&quot;ab&quot;:&quot;new&quot;}" class="tag-link" href="https://www.csdn.net/tags/MtTaEg0sMDUyNzctYmxvZwO0O0OO0O0O.html" target="_blank" rel="noopener">udp</a>
                                <a data-report-click="{&quot;mod&quot;:&quot;popu_626&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4223&quot;,&quot;strategy&quot;:&quot;网络通信&quot;,&quot;ab&quot;:&quot;new&quot;}" class="tag-link" href="https://www.csdn.net/tags/MtTaEg0sMDk4MzItYmxvZwO0O0OO0O0O.html" target="_blank" rel="noopener">网络通信</a>
                    </div>
                </div>
                <div class="slide-content-box">
                    <div class="article-copyright">
                        <div class="creativecommons">
                            版权声明：本文为博主原创文章，遵循<a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="noopener"> CC 4.0 BY-SA </a>版权协议，转载请附上原文出处链接和本声明。
                        </div>
                        <div class="article-source-link">
                            本文链接：<a href="https://blog.csdn.net/twj1248445531/article/details/111032255" target="_blank">https://blog.csdn.net/twj1248445531/article/details/111032255</a>
                        </div>
                    </div>
                </div>
                <div class="operating">
                    <a class="href-article-edit slide-toggle">版权</a>
                </div>
            </div>
        </div>
    </div>
    <div id="csdn-shop-window-top" class="csdn-shop-window-common" style="margin-top: 18px; padding: 0px; display: none;"></div>
    <article class="baidu_pl">
        <div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/ck_htmledit_views-b5506197d8.css">
                <div id="content_views" class="markdown_views prism-atom-one-dark">
                    <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                    </svg>
                    <p><font color="#999AAA">本学期计算机网络课程要求完成一个TCP和一个UDP的通信程序，我完成了功能的简单实现。我在上一篇博客已经讲了TCP的具体实现，接下来讲一讲UDP程序的实现。<br> </font></p> 
<hr color="#000000" size="1&quot;"> 
<p></p>
<div class="toc">
 <h3><a name="t0"></a><a name="t0"></a>目录</h3>
 <ul><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#_11" target="_self">效果展示</a></li><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#_19" target="_self">一、项目结构</a></li><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#_34" target="_self">二、完整代码</a></li><li><ul><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#1UDPClient_35" target="_self">1.UDPClient</a></li><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#2UDPServer_109" target="_self">2.UDPServer</a></li><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#3UDPFrame_176" target="_self">3.UDPFrame</a></li><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#4UDPSend_323" target="_self">4.UDPSend</a></li><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#5UDPReceive_372" target="_self">5.UDPReceive</a></li><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#6ReminderTextAdapter_415" target="_self">6.ReminderTextAdapter（参考别人的，非原创）</a></li></ul>
  </li><li><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#_461" target="_self">总结</a></li></ul>
</div>
<p></p> 
<hr color="#000000" size="1&quot;"> 
<h1><a name="t1"></a><a name="t1"></a><a id="_11"></a>效果展示</h1> 
<p><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201211113815381.png" alt="初始界面"><br> <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201211113900426.png" alt="连接成功"><br> <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201211114000670.png" alt="互发消息"></p> 
<p><font color="#999AAA">以下是具体实现过程：</font></p> 
<h1><a name="t2"></a><a name="t2"></a><a id="_19"></a>一、项目结构</h1> 
<p><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201211114112232.png" alt="项目结构"></p> 
<font color="#999AAA"> 下面说说每个类的具体作用： </font>
<p><strong>UDPClient</strong>：UDP客户端的核心代码部分；<br> <strong>UDPServer</strong>：UDP服务器端的核心代码部分;<br> <strong>UDPFrame</strong>：UDP客户端和服务器端的界面搭建；<br> <strong>UDPSend</strong>：UDP客户端或服务器端的一端向另一端发送消息；<br> <strong>UDPReceive</strong>：UDP客户端或服务器端的一端接收另一端发送的消息；<br> <strong>ReminderTextAdapter</strong>：网上查阅的代码，非核心内容实现部分，主要用于灰色提示字hint功能的实现（swing中的实现方法不太熟悉）；</p> 
<p>注：在UDP通信中，没有TCP那样明确的ServerSocket，只是通过Datagram数据报的方式传递给另外的DatagramSocket，因此本项目中虽然有客户端与服务器端的区别，但本质上二者并无区别（即客户端与服务器端实现方式基本相同），因此客户端和服务器端需要的界面布局也相同，故我也把二者的界面抽取成了一个类，在此特地说明一下。</p> 
<h1><a name="t3"></a><a name="t3"></a><a id="_34"></a>二、完整代码</h1> 
<h2><a name="t4"></a><a name="t4"></a><a id="1UDPClient_35"></a>1.UDPClient</h2> 
<p><font color="#999AAA">代码如下：</font></p> 
<pre class="prettyprint"><code class="prism language-java has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token keyword">package</span> udpCommunication<span class="token punctuation">;</span>

<span class="token keyword">import</span> javax<span class="token punctuation">.</span>swing<span class="token punctuation">.</span>*<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span>event<span class="token punctuation">.</span>ActionEvent<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span>event<span class="token punctuation">.</span>ActionListener<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>io<span class="token punctuation">.</span>IOException<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>net<span class="token punctuation">.</span>DatagramPacket<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>net<span class="token punctuation">.</span>DatagramSocket<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UDPClient</span> <span class="token keyword">implements</span> <span class="token class-name">ActionListener</span><span class="token punctuation">,</span> Runnable <span class="token punctuation">{<!-- --></span>
    <span class="token keyword">private</span> DatagramSocket datagramSocket<span class="token punctuation">;</span>
    <span class="token keyword">private</span> Thread thread <span class="token operator">=</span> null<span class="token punctuation">;</span>
    <span class="token keyword">private</span> UDPFrame clientFrame<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token function">UDPClient</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        JPanel panel <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JPanel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        clientFrame <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">UDPFrame</span><span class="token punctuation">(</span><span class="token string">"UDPClient"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        clientFrame<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>panel<span class="token punctuation">)</span><span class="token punctuation">;</span>

        clientFrame<span class="token punctuation">.</span><span class="token function">placeComponents</span><span class="token punctuation">(</span>panel<span class="token punctuation">)</span><span class="token punctuation">;</span>
        clientFrame<span class="token punctuation">.</span><span class="token function">setVisible</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        clientFrame<span class="token punctuation">.</span><span class="token function">getConnect</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addActionListener</span><span class="token punctuation">(</span>e <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token punctuation">{<!-- --></span>
            <span class="token keyword">try</span> <span class="token punctuation">{<!-- --></span>
                <span class="token comment">//host:"127.0.0.1"</span>
                <span class="token comment">//String host = UDPClientFrame.getIpField().getText();</span>
                <span class="token comment">//port:8887</span>
                <span class="token keyword">int</span> dSocketPort <span class="token operator">=</span> Integer<span class="token punctuation">.</span><span class="token function">parseInt</span><span class="token punctuation">(</span>clientFrame<span class="token punctuation">.</span><span class="token function">getDSocketField</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                datagramSocket <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatagramSocket</span><span class="token punctuation">(</span>dSocketPort<span class="token punctuation">)</span><span class="token punctuation">;</span>
                clientFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"[连接] : 正在连接中……\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                clientFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"\t连接成功\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                thread <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Thread</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                thread<span class="token punctuation">.</span><span class="token function">setPriority</span><span class="token punctuation">(</span>Thread<span class="token punctuation">.</span>MIN_PRIORITY<span class="token punctuation">)</span><span class="token punctuation">;</span>
                thread<span class="token punctuation">.</span><span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">IOException</span> ex<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
                ex<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        clientFrame<span class="token punctuation">.</span><span class="token function">getTransmit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addActionListener</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        clientFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"……UDP客户端启动……\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"……UDP客户端启动……\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">new</span> <span class="token class-name">UDPClient</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//向服务器端发送数据</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">actionPerformed</span><span class="token punctuation">(</span>ActionEvent e<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token comment">//String send = UDPClientFrame.getSendField().getText();</span>
        <span class="token comment">//port:8888</span>
        <span class="token comment">//发送消息</span>
        <span class="token keyword">new</span> <span class="token class-name">UDPSend</span><span class="token punctuation">(</span>datagramSocket<span class="token punctuation">,</span> clientFrame<span class="token punctuation">,</span> <span class="token string">"客户端"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">sendMessages</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//使用线程处理客户端接收服务器端的数据</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> bytes <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">byte</span><span class="token punctuation">[</span><span class="token number">1024</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        DatagramPacket datagramPacket <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatagramPacket</span><span class="token punctuation">(</span>bytes<span class="token punctuation">,</span> bytes<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">new</span> <span class="token class-name">UDPReceive</span><span class="token punctuation">(</span>datagramSocket<span class="token punctuation">,</span> datagramPacket<span class="token punctuation">,</span> clientFrame<span class="token punctuation">,</span> <span class="token string">"服务器端"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">receiveMessages</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li></ul></pre> 
<h2><a name="t5"></a><a name="t5"></a><a id="2UDPServer_109"></a>2.UDPServer</h2> 
<p><font color="#999AAA">代码如下：</font></p> 
<pre class="prettyprint"><code class="prism language-java has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token keyword">package</span> udpCommunication<span class="token punctuation">;</span>

<span class="token keyword">import</span> javax<span class="token punctuation">.</span>swing<span class="token punctuation">.</span>*<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span>event<span class="token punctuation">.</span>ActionEvent<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span>event<span class="token punctuation">.</span>ActionListener<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>io<span class="token punctuation">.</span>IOException<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>net<span class="token punctuation">.</span>*<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UDPServer</span> <span class="token keyword">implements</span> <span class="token class-name">ActionListener</span><span class="token punctuation">,</span> Runnable <span class="token punctuation">{<!-- --></span>
    <span class="token keyword">private</span> DatagramSocket datagramSocket<span class="token punctuation">;</span>
    <span class="token keyword">private</span> Thread thread <span class="token operator">=</span> null<span class="token punctuation">;</span>
    <span class="token keyword">private</span> UDPFrame serverFrame<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token function">UDPServer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        serverFrame <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">UDPFrame</span><span class="token punctuation">(</span><span class="token string">"UDPServer"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        JPanel panel <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JPanel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        serverFrame<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>panel<span class="token punctuation">)</span><span class="token punctuation">;</span>

        serverFrame<span class="token punctuation">.</span><span class="token function">placeComponents</span><span class="token punctuation">(</span>panel<span class="token punctuation">)</span><span class="token punctuation">;</span>
        serverFrame<span class="token punctuation">.</span><span class="token function">setVisible</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">//port:8888</span>
        serverFrame<span class="token punctuation">.</span><span class="token function">getConnect</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addActionListener</span><span class="token punctuation">(</span>e <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token punctuation">{<!-- --></span>
            <span class="token keyword">try</span> <span class="token punctuation">{<!-- --></span>
                <span class="token keyword">int</span> dSocketPort <span class="token operator">=</span> Integer<span class="token punctuation">.</span><span class="token function">parseInt</span><span class="token punctuation">(</span>serverFrame<span class="token punctuation">.</span><span class="token function">getDSocketField</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                datagramSocket <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatagramSocket</span><span class="token punctuation">(</span>dSocketPort<span class="token punctuation">)</span><span class="token punctuation">;</span>

                serverFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"[连接] : 正在连接中……\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                serverFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"\t连接成功\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                thread <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Thread</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                thread<span class="token punctuation">.</span><span class="token function">setPriority</span><span class="token punctuation">(</span>Thread<span class="token punctuation">.</span>MIN_PRIORITY<span class="token punctuation">)</span><span class="token punctuation">;</span>
                thread<span class="token punctuation">.</span><span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">IOException</span> ex<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
                ex<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        serverFrame<span class="token punctuation">.</span><span class="token function">getTransmit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addActionListener</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        serverFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"……UDP服务器启动……\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"……UDP服务器启动……\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">new</span> <span class="token class-name">UDPServer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//向客户端发送数据</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">actionPerformed</span><span class="token punctuation">(</span>ActionEvent e<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">new</span> <span class="token class-name">UDPSend</span><span class="token punctuation">(</span>datagramSocket<span class="token punctuation">,</span> serverFrame<span class="token punctuation">,</span> <span class="token string">"服务器端"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">sendMessages</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//使用线程处理服务器端接收客户端的数据</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> bytes <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">byte</span><span class="token punctuation">[</span><span class="token number">1024</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        DatagramPacket datagramPacket <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatagramPacket</span><span class="token punctuation">(</span>bytes<span class="token punctuation">,</span> bytes<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">new</span> <span class="token class-name">UDPReceive</span><span class="token punctuation">(</span>datagramSocket<span class="token punctuation">,</span> datagramPacket<span class="token punctuation">,</span> serverFrame<span class="token punctuation">,</span> <span class="token string">"客户端"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">receiveMessages</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li></ul></pre> 
<h2><a name="t6"></a><a name="t6"></a><a id="3UDPFrame_176"></a>3.UDPFrame</h2> 
<p><font color="#999AAA">代码如下：</font></p> 
<pre class="prettyprint"><code class="prism language-java has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token keyword">package</span> udpCommunication<span class="token punctuation">;</span>

<span class="token keyword">import</span> javax<span class="token punctuation">.</span>swing<span class="token punctuation">.</span>*<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span>*<span class="token punctuation">;</span>

<span class="token comment">/**
 * ip
 * DatagramSocket(hint:port)
 * DatagramPacket(hint:port)
 * send
 * showArea
 */</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UDPFrame</span> <span class="token keyword">extends</span> <span class="token class-name">JFrame</span> <span class="token punctuation">{<!-- --></span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> JTextField ipField<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> JTextField dSocketField<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> JTextField dPacketField<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> JTextField sendField<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> JTextArea textArea<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> JButton connect<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> JButton transmit<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token function">UDPFrame</span><span class="token punctuation">(</span>String title<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token function">setSize</span><span class="token punctuation">(</span><span class="token number">700</span><span class="token punctuation">,</span> <span class="token number">480</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">setLocationRelativeTo</span><span class="token punctuation">(</span>null<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//居中显示</span>
        <span class="token function">setResizable</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//设置不允许改变窗体大小</span>
        <span class="token function">setDefaultCloseOperation</span><span class="token punctuation">(</span>JFrame<span class="token punctuation">.</span>EXIT_ON_CLOSE<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">setTitle</span><span class="token punctuation">(</span>title<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> JTextField <span class="token function">getIpField</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">return</span> ipField<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> JTextField <span class="token function">getDSocketField</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">return</span> dSocketField<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> JTextField <span class="token function">getDPacketField</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">return</span> dPacketField<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> JTextField <span class="token function">getSendField</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">return</span> sendField<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> JTextArea <span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">return</span> textArea<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> JButton <span class="token function">getConnect</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">return</span> connect<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> JButton <span class="token function">getTransmit</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">return</span> transmit<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">placeComponents</span><span class="token punctuation">(</span>JPanel panel<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        panel<span class="token punctuation">.</span><span class="token function">setLayout</span><span class="token punctuation">(</span>null<span class="token punctuation">)</span><span class="token punctuation">;</span>
        Font font1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Font</span><span class="token punctuation">(</span><span class="token string">"宋体"</span><span class="token punctuation">,</span> Font<span class="token punctuation">.</span>BOLD<span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Font font2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Font</span><span class="token punctuation">(</span><span class="token string">"宋体"</span><span class="token punctuation">,</span> Font<span class="token punctuation">.</span>PLAIN<span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">//创建JLabel</span>
        JLabel ip <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JLabel</span><span class="token punctuation">(</span><span class="token string">"IP"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        ip<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font1<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//设置JLabel的字体</span>
        ip<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>ip<span class="token punctuation">)</span><span class="token punctuation">;</span>

        JLabel dSocketLabel <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JLabel</span><span class="token punctuation">(</span><span class="token string">"DatagramSocket"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        dSocketLabel<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font1<span class="token punctuation">)</span><span class="token punctuation">;</span>
        dSocketLabel<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">65</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>dSocketLabel<span class="token punctuation">)</span><span class="token punctuation">;</span>

        JLabel dPacketLabel <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JLabel</span><span class="token punctuation">(</span><span class="token string">"DatagramPacket"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        dPacketLabel<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font1<span class="token punctuation">)</span><span class="token punctuation">;</span>
        dPacketLabel<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>dPacketLabel<span class="token punctuation">)</span><span class="token punctuation">;</span>

        JLabel send <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JLabel</span><span class="token punctuation">(</span><span class="token string">"Send"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        send<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font1<span class="token punctuation">)</span><span class="token punctuation">;</span>
        send<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>send<span class="token punctuation">)</span><span class="token punctuation">;</span>

        JLabel text <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JLabel</span><span class="token punctuation">(</span><span class="token string">"Text"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        text<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font1<span class="token punctuation">)</span><span class="token punctuation">;</span>
        text<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">80</span><span class="token punctuation">,</span> <span class="token number">170</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">//创建文本域</span>
        ipField <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JTextField</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        ipField<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font2<span class="token punctuation">)</span><span class="token punctuation">;</span>
        ipField<span class="token punctuation">.</span><span class="token function">addFocusListener</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ReminderTextAdapter</span><span class="token punctuation">(</span>ipField<span class="token punctuation">,</span> <span class="token string">"默认：127.0.0.1"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        ipField<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>ipField<span class="token punctuation">)</span><span class="token punctuation">;</span>

        dSocketField <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JTextField</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        dSocketField<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font2<span class="token punctuation">)</span><span class="token punctuation">;</span>
        dSocketField<span class="token punctuation">.</span><span class="token function">addFocusListener</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ReminderTextAdapter</span><span class="token punctuation">(</span>dSocketField<span class="token punctuation">,</span> <span class="token string">"port:"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        dSocketField<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">65</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>dSocketField<span class="token punctuation">)</span><span class="token punctuation">;</span>

        dPacketField <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JTextField</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        dPacketField<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font2<span class="token punctuation">)</span><span class="token punctuation">;</span>
        dPacketField<span class="token punctuation">.</span><span class="token function">addFocusListener</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ReminderTextAdapter</span><span class="token punctuation">(</span>dPacketField<span class="token punctuation">,</span> <span class="token string">"port:"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        dPacketField<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>dPacketField<span class="token punctuation">)</span><span class="token punctuation">;</span>

        sendField <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JTextField</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sendField<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font2<span class="token punctuation">)</span><span class="token punctuation">;</span>
        sendField<span class="token punctuation">.</span><span class="token function">addFocusListener</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ReminderTextAdapter</span><span class="token punctuation">(</span>sendField<span class="token punctuation">,</span> <span class="token string">"请输入要发送的信息:"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sendField<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>sendField<span class="token punctuation">)</span><span class="token punctuation">;</span>

        textArea <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        textArea<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font2<span class="token punctuation">)</span><span class="token punctuation">;</span>
        textArea<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">170</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        textArea<span class="token punctuation">.</span><span class="token function">setEditable</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        textArea<span class="token punctuation">.</span><span class="token function">setLineWrap</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>textArea<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">//给textArea添加滚动条</span>
        JScrollPane scrollPane <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JScrollPane</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        scrollPane<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">220</span><span class="token punctuation">,</span> <span class="token number">170</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">160</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        scrollPane<span class="token punctuation">.</span><span class="token function">setVerticalScrollBarPolicy</span><span class="token punctuation">(</span>JScrollPane<span class="token punctuation">.</span>VERTICAL_SCROLLBAR_ALWAYS<span class="token punctuation">)</span><span class="token punctuation">;</span>
        scrollPane<span class="token punctuation">.</span><span class="token function">setHorizontalScrollBarPolicy</span><span class="token punctuation">(</span>JScrollPane<span class="token punctuation">.</span>HORIZONTAL_SCROLLBAR_AS_NEEDED<span class="token punctuation">)</span><span class="token punctuation">;</span>

        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>scrollPane<span class="token punctuation">)</span><span class="token punctuation">;</span>
        scrollPane<span class="token punctuation">.</span><span class="token function">setViewportView</span><span class="token punctuation">(</span>textArea<span class="token punctuation">)</span><span class="token punctuation">;</span>


        <span class="token comment">//添加两个按钮</span>
        connect <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JButton</span><span class="token punctuation">(</span><span class="token string">"连接"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        connect<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font1<span class="token punctuation">)</span><span class="token punctuation">;</span>
        connect<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">140</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>connect<span class="token punctuation">)</span><span class="token punctuation">;</span>

        transmit <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JButton</span><span class="token punctuation">(</span><span class="token string">"发送"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        transmit<span class="token punctuation">.</span><span class="token function">setFont</span><span class="token punctuation">(</span>font1<span class="token punctuation">)</span><span class="token punctuation">;</span>
        transmit<span class="token punctuation">.</span><span class="token function">setBounds</span><span class="token punctuation">(</span><span class="token number">440</span><span class="token punctuation">,</span> <span class="token number">360</span><span class="token punctuation">,</span> <span class="token number">115</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panel<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>transmit<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li><li style="color: rgb(153, 153, 153);">69</li><li style="color: rgb(153, 153, 153);">70</li><li style="color: rgb(153, 153, 153);">71</li><li style="color: rgb(153, 153, 153);">72</li><li style="color: rgb(153, 153, 153);">73</li><li style="color: rgb(153, 153, 153);">74</li><li style="color: rgb(153, 153, 153);">75</li><li style="color: rgb(153, 153, 153);">76</li><li style="color: rgb(153, 153, 153);">77</li><li style="color: rgb(153, 153, 153);">78</li><li style="color: rgb(153, 153, 153);">79</li><li style="color: rgb(153, 153, 153);">80</li><li style="color: rgb(153, 153, 153);">81</li><li style="color: rgb(153, 153, 153);">82</li><li style="color: rgb(153, 153, 153);">83</li><li style="color: rgb(153, 153, 153);">84</li><li style="color: rgb(153, 153, 153);">85</li><li style="color: rgb(153, 153, 153);">86</li><li style="color: rgb(153, 153, 153);">87</li><li style="color: rgb(153, 153, 153);">88</li><li style="color: rgb(153, 153, 153);">89</li><li style="color: rgb(153, 153, 153);">90</li><li style="color: rgb(153, 153, 153);">91</li><li style="color: rgb(153, 153, 153);">92</li><li style="color: rgb(153, 153, 153);">93</li><li style="color: rgb(153, 153, 153);">94</li><li style="color: rgb(153, 153, 153);">95</li><li style="color: rgb(153, 153, 153);">96</li><li style="color: rgb(153, 153, 153);">97</li><li style="color: rgb(153, 153, 153);">98</li><li style="color: rgb(153, 153, 153);">99</li><li style="color: rgb(153, 153, 153);">100</li><li style="color: rgb(153, 153, 153);">101</li><li style="color: rgb(153, 153, 153);">102</li><li style="color: rgb(153, 153, 153);">103</li><li style="color: rgb(153, 153, 153);">104</li><li style="color: rgb(153, 153, 153);">105</li><li style="color: rgb(153, 153, 153);">106</li><li style="color: rgb(153, 153, 153);">107</li><li style="color: rgb(153, 153, 153);">108</li><li style="color: rgb(153, 153, 153);">109</li><li style="color: rgb(153, 153, 153);">110</li><li style="color: rgb(153, 153, 153);">111</li><li style="color: rgb(153, 153, 153);">112</li><li style="color: rgb(153, 153, 153);">113</li><li style="color: rgb(153, 153, 153);">114</li><li style="color: rgb(153, 153, 153);">115</li><li style="color: rgb(153, 153, 153);">116</li><li style="color: rgb(153, 153, 153);">117</li><li style="color: rgb(153, 153, 153);">118</li><li style="color: rgb(153, 153, 153);">119</li><li style="color: rgb(153, 153, 153);">120</li><li style="color: rgb(153, 153, 153);">121</li><li style="color: rgb(153, 153, 153);">122</li><li style="color: rgb(153, 153, 153);">123</li><li style="color: rgb(153, 153, 153);">124</li><li style="color: rgb(153, 153, 153);">125</li><li style="color: rgb(153, 153, 153);">126</li><li style="color: rgb(153, 153, 153);">127</li><li style="color: rgb(153, 153, 153);">128</li><li style="color: rgb(153, 153, 153);">129</li><li style="color: rgb(153, 153, 153);">130</li><li style="color: rgb(153, 153, 153);">131</li><li style="color: rgb(153, 153, 153);">132</li><li style="color: rgb(153, 153, 153);">133</li><li style="color: rgb(153, 153, 153);">134</li><li style="color: rgb(153, 153, 153);">135</li><li style="color: rgb(153, 153, 153);">136</li><li style="color: rgb(153, 153, 153);">137</li><li style="color: rgb(153, 153, 153);">138</li><li style="color: rgb(153, 153, 153);">139</li><li style="color: rgb(153, 153, 153);">140</li><li style="color: rgb(153, 153, 153);">141</li><li style="color: rgb(153, 153, 153);">142</li></ul></pre> 
<h2><a name="t7"></a><a name="t7"></a><a id="4UDPSend_323"></a>4.UDPSend</h2> 
<p><font color="#999AAA">代码如下：</font></p> 
<pre class="prettyprint"><code class="prism language-java has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token keyword">package</span> udpCommunication<span class="token punctuation">;</span>

<span class="token keyword">import</span> java<span class="token punctuation">.</span>net<span class="token punctuation">.</span>DatagramPacket<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>net<span class="token punctuation">.</span>DatagramSocket<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>net<span class="token punctuation">.</span>InetAddress<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UDPSend</span> <span class="token punctuation">{<!-- --></span>
    <span class="token keyword">private</span> DatagramSocket datagramSocket<span class="token punctuation">;</span>
    <span class="token keyword">private</span> UDPFrame udpFrame<span class="token punctuation">;</span>
    <span class="token keyword">private</span> String sender<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token function">UDPSend</span><span class="token punctuation">(</span>DatagramSocket datagramSocket<span class="token punctuation">,</span> UDPFrame udpFrame<span class="token punctuation">,</span> String sender<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>datagramSocket <span class="token operator">=</span> datagramSocket<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>udpFrame <span class="token operator">=</span> udpFrame<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>sender <span class="token operator">=</span> sender<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">sendMessages</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token comment">//String send = UDPServerFrame.getSendField().getText();</span>
        <span class="token comment">//发送消息</span>
        <span class="token keyword">try</span> <span class="token punctuation">{<!-- --></span>
            System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"请输入"</span> <span class="token operator">+</span> sender <span class="token operator">+</span> <span class="token string">"要发送的消息:"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            String data <span class="token operator">=</span> udpFrame<span class="token punctuation">.</span><span class="token function">getSendField</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            String ip <span class="token operator">=</span> udpFrame<span class="token punctuation">.</span><span class="token function">getIpField</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">int</span> dPacketPort <span class="token operator">=</span> Integer<span class="token punctuation">.</span><span class="token function">parseInt</span><span class="token punctuation">(</span>udpFrame<span class="token punctuation">.</span><span class="token function">getDPacketField</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> bytes <span class="token operator">=</span> data<span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            InetAddress inetAddress <span class="token operator">=</span> InetAddress<span class="token punctuation">.</span><span class="token function">getByName</span><span class="token punctuation">(</span>ip<span class="token punctuation">)</span><span class="token punctuation">;</span>
            DatagramPacket datagramPacket <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatagramPacket</span><span class="token punctuation">(</span>bytes<span class="token punctuation">,</span> bytes<span class="token punctuation">.</span>length<span class="token punctuation">,</span> inetAddress<span class="token punctuation">,</span> dPacketPort<span class="token punctuation">)</span><span class="token punctuation">;</span>
            datagramSocket<span class="token punctuation">.</span><span class="token function">send</span><span class="token punctuation">(</span>datagramPacket<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">//udpFrame.getTextArea().append("\t" + sender + "发送消息成功\n");</span>
            udpFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"\t\t\t["</span> <span class="token operator">+</span> sender <span class="token operator">+</span> <span class="token string">"] : "</span> <span class="token operator">+</span> data <span class="token operator">+</span> <span class="token string">"\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            String ipAddress <span class="token operator">=</span> datagramPacket<span class="token punctuation">.</span><span class="token function">getAddress</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getHostAddress</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"ipAddress: "</span> <span class="token operator">+</span> ipAddress<span class="token punctuation">)</span><span class="token punctuation">;</span>
            System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"ipField().getText(): "</span> <span class="token operator">+</span> ip<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> ex<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
            ex<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            udpFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"\t"</span> <span class="token operator">+</span> sender <span class="token operator">+</span> <span class="token string">"尚未连接成功，消息发送失败\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{<!-- --></span>
            <span class="token comment">//System.out.println("\t"+sender+"发送消息成功\n");</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li></ul></pre> 
<h2><a name="t8"></a><a name="t8"></a><a id="5UDPReceive_372"></a>5.UDPReceive</h2> 
<p><font color="#999AAA">代码如下：</font></p> 
<pre class="prettyprint"><code class="prism language-java has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token keyword">package</span> udpCommunication<span class="token punctuation">;</span>

<span class="token keyword">import</span> java<span class="token punctuation">.</span>net<span class="token punctuation">.</span>DatagramPacket<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>net<span class="token punctuation">.</span>DatagramSocket<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UDPReceive</span> <span class="token punctuation">{<!-- --></span>
    <span class="token keyword">private</span> DatagramSocket datagramSocket<span class="token punctuation">;</span>
    <span class="token keyword">private</span> DatagramPacket datagramPacket<span class="token punctuation">;</span>
    <span class="token keyword">private</span> UDPFrame udpFrame<span class="token punctuation">;</span>
    <span class="token keyword">private</span> String sender<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token function">UDPReceive</span><span class="token punctuation">(</span>DatagramSocket datagramSocket<span class="token punctuation">,</span> DatagramPacket datagramPacket<span class="token punctuation">,</span> UDPFrame udpFrame<span class="token punctuation">,</span> String sender<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>datagramSocket <span class="token operator">=</span> datagramSocket<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>datagramPacket <span class="token operator">=</span> datagramPacket<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>udpFrame <span class="token operator">=</span> udpFrame<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>sender <span class="token operator">=</span> sender<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">receiveMessages</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">try</span> <span class="token punctuation">{<!-- --></span>
            <span class="token keyword">while</span> <span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
                <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> bytes <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">byte</span><span class="token punctuation">[</span><span class="token number">1024</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
                datagramPacket <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DatagramPacket</span><span class="token punctuation">(</span>bytes<span class="token punctuation">,</span> bytes<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span>
                datagramSocket<span class="token punctuation">.</span><span class="token function">receive</span><span class="token punctuation">(</span>datagramPacket<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> data <span class="token operator">=</span> datagramPacket<span class="token punctuation">.</span><span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                String string <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">String</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> datagramPacket<span class="token punctuation">.</span><span class="token function">getLength</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                udpFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">"["</span> <span class="token operator">+</span> sender <span class="token operator">+</span> <span class="token string">"] : "</span> <span class="token operator">+</span> string <span class="token operator">+</span> <span class="token string">"\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                Thread<span class="token punctuation">.</span><span class="token function">sleep</span><span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
            e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            udpFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>sender <span class="token operator">+</span> <span class="token string">"异常\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            udpFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>sender <span class="token operator">+</span> <span class="token string">"与客户端连接中断\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{<!-- --></span>
            udpFrame<span class="token punctuation">.</span><span class="token function">getTextArea</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>sender <span class="token operator">+</span> <span class="token string">"关闭\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li></ul></pre> 
<h2><a name="t9"></a><a name="t9"></a><a id="6ReminderTextAdapter_415"></a>6.ReminderTextAdapter（参考别人的，非原创）</h2> 
<p><font color="#999AAA">代码如下：</font></p> 
<pre class="prettyprint"><code class="prism language-java has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token keyword">package</span> udpCommunication<span class="token punctuation">;</span>

<span class="token keyword">import</span> javax<span class="token punctuation">.</span>swing<span class="token punctuation">.</span>*<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span>*<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span>event<span class="token punctuation">.</span>FocusAdapter<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>awt<span class="token punctuation">.</span>event<span class="token punctuation">.</span>FocusEvent<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ReminderTextAdapter</span> <span class="token keyword">extends</span> <span class="token class-name">FocusAdapter</span> <span class="token punctuation">{<!-- --></span>
    <span class="token comment">//JTextField提示文字通用方法</span>
    JTextField textField<span class="token punctuation">;</span>
    String reminderString<span class="token punctuation">;</span>

    <span class="token comment">//初始化</span>
    <span class="token keyword">public</span> <span class="token function">ReminderTextAdapter</span><span class="token punctuation">(</span>JTextField textField<span class="token punctuation">,</span> String reminderString<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>textField <span class="token operator">=</span> textField<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>reminderString <span class="token operator">=</span> reminderString<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//焦点获得</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">focusGained</span><span class="token punctuation">(</span>FocusEvent e<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        String tempString <span class="token operator">=</span> textField<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//String tempString = this.getText();</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>tempString<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>reminderString<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
            textField<span class="token punctuation">.</span><span class="token function">setText</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            textField<span class="token punctuation">.</span><span class="token function">setForeground</span><span class="token punctuation">(</span>Color<span class="token punctuation">.</span>BLACK<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//焦点失去</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">focusLost</span><span class="token punctuation">(</span>FocusEvent e<span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
        String tempString <span class="token operator">=</span> textField<span class="token punctuation">.</span><span class="token function">getText</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>tempString<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>
            textField<span class="token punctuation">.</span><span class="token function">setForeground</span><span class="token punctuation">(</span>Color<span class="token punctuation">.</span>GRAY<span class="token punctuation">)</span><span class="token punctuation">;</span>
            textField<span class="token punctuation">.</span><span class="token function">setText</span><span class="token punctuation">(</span>reminderString<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li></ul></pre> 
<h1><a name="t10"></a><a name="t10"></a><a id="_461"></a>总结</h1> 
<p><font color="#999AAA">该项目简单的实现了UDP客户端和服务器端的通信，但是功能比较简单，页面也比较简洁，没有实现多个客户端互聊的功能等，还有待完善。</font></p> 
<hr color="#000000" size="1&quot;"> 刚开始写博客，大家觉得不错的点个赞吧！如果大家有什么建议或者问题的，欢迎评论，我会尽量与大家探讨问题的。
                </div><div><div></div></div>
                <link href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/markdown_views-d7a94ec6ab.css" rel="stylesheet">
                <link href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/style-f1c5feb645.css" rel="stylesheet">
        </div>
    </article>
</div>
            <div id="csdn-shop-window" class="csdn-shop-window-common"></div>
<div class="more-toolbox more-toolbox-active" id="toolBarBox">
    <span id="fixedBar"></span>
    <div class="left-toolbox" style="position: fixed; left: 373px; bottom: 0px; width: 1010px;">
        <ul class="toolbox-list ">
            <li class="tool-item tool-item-size tool-active is-like" id="is-like"><a>
            <img style="display:none;" id="is-like-imgactive-animation-like" class="animation-dom active-animation" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarThumbUpactive.png" alt="">
            <img class="isactive" style="display:none" id="is-like-imgactive" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarThumbUpactive.png" alt="">
            <img class="isdefault" style="display:block" id="is-like-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarThumbUp.png" alt="">   
            <span class="name" id="is-like-span" style="">点赞</span>
            <span id="spanCount" class="count" style="">
                    3
            </span>
            </a></li>
            <li class="tool-item tool-item-size tool-active tool-item-comment">
                <a href="https://blog.csdn.net/twj1248445531/article/details/111032255#commentBox">
                    <img class="isdefault" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarComment.png" alt="" style="display: block;">
                    <img class="isactive" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarCommentactive.png" style="display: none;" alt="">
                    <span class="name">评论</span>
                    <span class="count">
                        4
                    </span>
                </a>
            </li>
            <li class="tool-item tool-item-size tool-active tool-QRcode" id="tool-share" data-flag="">
                <a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;1582594662_002&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4129&quot;,&quot;ab&quot;:&quot;new&quot;}">
                    <img class="isdefault" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarShare.png" alt="" style="display: block;">
                    <img class="isactive" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarShareactive.png" style="display: none;" alt="">
                    <span class="name" style="">分享</span>
                </a>
                <div class="QRcode" id="tool-QRcode" style="left:-92%;">
                    <span id="QRcode-close">x</span>
                    <p class="title">
                    海报分享
                    </p>
                    <div id="shareCode" title="https://blog.csdn.net/twj1248445531/article/shareArticleCardPage?article_id=111032255&amp;utm_source=po_popup"><canvas width="144" height="144" style="display: none;"></canvas><img src="" style="display: block;"></div>
                    <p>
                    扫一扫，分享海报
                    </p>
                </div>
            </li>
            <li class="tool-item tool-item-size tool-active is-collection ">
                <a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4130&quot;,&quot;ab&quot;:&quot;new&quot;}">
                    <img style="display:none" id="is-collection-img-collection" class="animation-dom active-animation" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarCollectionActive.png" alt="">
                    <img class="isdefault" id="is-collection-img" style="display: block;" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarCollect.png" alt="">
                    <img class="isactive" id="is-collection-imgactive" style="display: none;" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarCollectionActive.png" alt="">
                    <span class="name" id="is-collection">收藏</span>
                    <span class="count get-collection" id="get-collection">
                        5
                    </span>
                </a>
            </li>
            <li class="tool-item tool-item-size tool-active tool-reward">
                <a id="toolreward" data-report-click="{&quot;mod&quot;:&quot;popu_830&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4237&quot;,&quot;dest&quot;:&quot;&quot;,&quot;ab&quot;:&quot;new&quot;}">
                    <img class="isdefault" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarReward.png" alt="" style="display: block;">
                    <img class="isactive" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarRewardactive.png" style="display: none;" alt="">
                    <span class="name">打赏</span>
                </a>
<div id="reward" class="reward-box">
	<p class="rewad-title">打赏<span class="reward-close"><svg t="1567152543821" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10924" xmlns:xlink="http://www.w3.org/1999/xlink" width="12" height="12"><defs><style type="text/css"></style></defs><path d="M512 438.378667L806.506667 143.893333a52.032 52.032 0 1 1 73.6 73.621334L585.621333 512l294.485334 294.485333a52.074667 52.074667 0 0 1-73.6 73.642667L512 585.621333 217.514667 880.128a52.053333 52.053333 0 1 1-73.621334-73.642667L438.378667 512 143.893333 217.514667a52.053333 52.053333 0 1 1 73.621334-73.621334L512 438.378667z" fill="" p-id="10925"></path></svg></span></p>
	<dl>
		<dd>
		<a href="https://blog.csdn.net/twj1248445531" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531&quot;,&quot;ab&quot;:&quot;new&quot;}">
			<img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/3_twj1248445531" class="avatar_pic">
		</a>
		</dd>
		<dt>
			<p class="blog-name">主旋律T</p>
			<p class="blog-discript">你的鼓励将是我创作的最大动力</p>
		</dt>
	</dl>
	<div class="change-bt-box">
		<span class="reward-bt reward-bt-coin">C币</span>
		<span class="reward-bt-space"></span>
		<span class="reward-bt reward-bt-money reward-bt-active">余额</span>
	</div>
	<div class="money-box">
			<span class="choose_money choosed" data-id="2">¥2</span>
			<span class="choose_money " data-id="4">¥4</span>
			<span class="choose_money " data-id="6">¥6</span>
			<span class="choose_money " data-id="10">¥10</span>
			<span class="choose_money " data-id="20">¥20</span>
			<span class="choose_money " data-id="50">¥50</span>
	</div>
	<div class="sure-box">
		<p class="is-have-money"><span class="tip">您的余额不足，请先充值哦～</span><a class="bt-go" data-report-click="{&quot;mod&quot;:&quot;1597646289_003&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4302&quot;}" target="_blank" href="https://i.csdn.net/#/wallet/balance/recharge" data-report-query="utm_source=RewardVip">去充值</a></p>
	</div>
</div>
            </li>
            <li class="tool-item tool-item-size tool-active tool-more">
              <a class="article-report">
                <img class="isdefault" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarReport.png" alt="" style="display: block;">
                <img class="isactive" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tobarReportactive.png" style="display: none;" alt="">
                <span class="name">举报</span>
              </a>
            </li>
            <li class="tool-item">
                    <a class="tool-attend tool-bt-button tool-bt-attend" href="javascript:;">关注</a>
                <a class="tool-item-follow active-animation" style="display:none;">关注</a>
            </li>
            <li class="tool-item">
                    <p class="company active" id="health-companies" href="javascript:;">一键三连</p>
            </li>
        </ul>
    </div>  
</div>
<script type="text/javascript" crossorigin="" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/qrcode-7c90a92189.min.js"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/saved_resource(3)" type="text/javascript"></script>
<script type="text/javascript" crossorigin="" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/user-login.js"></script>
<script type="text/javascript" crossorigin="" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/collection-box.js"></script>
                <div id="dmp_ad_58" style="width:100%;overflow-x:hidden"><div id="kp_box_58" data-pid="58"><iframe src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/saved_resource.html" frameborder="0" width="100%" height="75px" scrolling="no"></iframe><img class="pre-img-lasy" data-src="https://kunyu.csdn.net/1.png?p=58&amp;a=4252&amp;c=7488&amp;k=&amp;spm=1001.2101.3001.5002&amp;d=1&amp;t=3&amp;u=8b49ef51d6974ad7b6bc5df96ac0228e" style="display: block;width: 0px;height: 0px;" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/1.png"></div></div>
            <div class="second-recommend-box recommend-box">
<div class="recommend-item-box type_download clearfix" data-url="https://download.csdn.net/download/l332845135/2539214">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://download.csdn.net/download/l332845135/2539214" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-1.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;1&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/download/l332845135/2539214&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control">
					通过<em>UDP</em>将文件从服务器发送到<em>客户端</em>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block">07-13</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://download.csdn.net/download/l332845135/2539214" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-1.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;1&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/download/l332845135/2539214&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control">
				<div class="desc ellipsis-online ellipsis-online-1">通过<em>UDP</em>将文件从服务器发送到<em>客户端</em>
C# 网络服务端和<em>客户端</em>，<em>客户端</em>发送请求，服务端将文件发送到<em>客户端</em>，<em>客户端</em>进行接收</div>
			</a>
		</div>
	</div>
</div>
            </div>
<a id="commentBox" name="commentBox"></a>
<div class="comment-box">
	<div class="comment-edit-box d-flex">
		<a id="commentsedit"></a>
		<div class="user-img">
			<a href="https://blog.csdn.net/hwf453" target="_blank">
				<img class="" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/3_hwf453">
			</a>
		</div>
		<form id="commentform">
			
      <textarea class="comment-content" name="comment_content" id="comment_content" placeholder="优质评论可以帮助作者获得更高权重" maxlength="1000"></textarea>
			<div class="comment-emoticon"><img class="comment-emoticon-img" data-url="https://csdnimg.cn/release/blogv2/dist/pc/img/" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/emoticon.png" alt="表情包"></div> 
      <span class="comment-emoticon-tip">插入表情</span>
      <div class="comment-emoticon-box" style="display: none;">
        <div class="comment-emoticon-img-box">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:001.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/001.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:002.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/002.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:003.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/003.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:004.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/004.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:005.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/005.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:006.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/006.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:007.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/007.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:008.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/008.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:009.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/009.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:010.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/010.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:011.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/011.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:012.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/012.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:013.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/013.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:014.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/014.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:015.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/015.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:016.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/016.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:017.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/017.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:018.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/018.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:019.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/019.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:020.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/020.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:021.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/021.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:022.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/022.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:023.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/023.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:024.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/024.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:025.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/025.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:026.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/026.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:027.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/027.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:028.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/028.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:029.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/029.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:030.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/030.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:031.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/031.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:032.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/032.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:033.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/033.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:034.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/034.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:035.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/035.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:036.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/036.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:037.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/037.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:038.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/038.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:039.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/039.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:040.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/040.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:041.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/041.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:042.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/042.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:043.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/043.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:044.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/044.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:045.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/045.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:046.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/046.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:047.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/047.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:048.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/048.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:049.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/049.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:050.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/050.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:051.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/051.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:052.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/052.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:053.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/053.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:054.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/054.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:055.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/055.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:056.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/056.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:057.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/057.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:058.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/058.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:059.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/059.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:060.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/060.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:061.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/061.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:062.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/062.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:063.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/063.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:064.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/064.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:065.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/065.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:066.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/066.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:067.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/067.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:068.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/068.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:069.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/069.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:070.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/070.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:071.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/071.png">
            <img class="emoticon-monkey-img" data-emoticon="[face]emoji:072.png[/face]" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/072.png">
        </div>
      </div>
      <div class="opt-box">
				<div id="ubbtools" class="add_code">
					<a href="https://blog.csdn.net/twj1248445531/article/details/111032255#insertcode" code="code" target="_self"><i class="icon iconfont icon-daima"></i></a>
				</div>
				<input type="hidden" id="comment_replyId" name="comment_replyId">
				<input type="hidden" id="article_id" name="article_id" value="111032255">
				<input type="hidden" id="comment_userId" name="comment_userId" value="">
				<input type="hidden" id="commentId" name="commentId" value="">
				<div class="dropdown" id="myDrap">
					<a class="dropdown-face d-flex align-items-center" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
						<div class="txt-selected text-truncate">添加代码片</div>
						<svg class="icon d-block" width="200px" height="100.00px" viewBox="0 0 2048 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M597.33333292 298.666667h853.333334L1023.99999992 725.333333 597.33333292 298.666667z"></path></svg>
					</a>
					<ul class="dropdown-menu" id="commentCode" aria-labelledby="drop4">
						<li><a data-code="html">HTML/XML</a></li>
						<li><a data-code="objc">objective-c</a></li>
						<li><a data-code="ruby">Ruby</a></li>
						<li><a data-code="php">PHP</a></li>
						<li><a data-code="csharp">C</a></li>
						<li><a data-code="cpp">C++</a></li>
						<li><a data-code="javascript">JavaScript</a></li>
						<li><a data-code="python">Python</a></li>
						<li><a data-code="java">Java</a></li>
						<li><a data-code="css">CSS</a></li>
						<li><a data-code="sql">SQL</a></li>
						<li><a data-code="plain">其它</a></li>
					</ul>
				</div>
				<div class="right-box" id="rightBox" data-type="2">
							<span id="tip_comment" class="tip">还能输入<em>1000</em>个字符</span>
							<a data-report-click="{&quot;mod&quot;:&quot;1582594662_003&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4227&quot;,&quot;ab&quot;:&quot;new&quot;}"><input type="submit" class="btn btn-sm btn-comment" value="发表评论"></a>
				</div>
			</div>
		</form>
		<input type="button" class="bt-comment-show" value="评论">
	</div>
	<div class="comment-list-container" style="display: block;">
		<a id="comments"></a>
		<div class="comment-list-box"><ul class="comment-list"><li class="comment-line-box d-flex" data-commentid="14196479" data-replyname="kimol_justdo"><div style="display: flex;width: 100%;">      <a target="_blank" href="https://blog.csdn.net/kimol_justdo"><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/3_kimol_justdo" username="kimol_justdo" alt="kimol_justdo" class="avatar"></a>        <div class="right-box ">          <div class="new-info-box clearfix">            <a target="_blank" href="https://blog.csdn.net/kimol_justdo"><span class="name ">不正经的kimol君</span></a><span class="colon">:</span><span class="floor-num"></span><span class="new-comment">学到了，点赞支持</span><span class="date" title="2020-12-13 22:09:20">6 月前</span><span class="new-opt-floating"><a class="btn-bt  btn-reply" data-type="reply" data-flag="true">回复</a><a class="btn-bt  btn-report"><img class="btn-report-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentMore.png" title=""><span data-type="report" class="hide-report">举报</span></a></span></div><div class="comment-like " data-commentid="14196479"><img class="comment-like-img unclickImg" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentUnHeart.png" title="点赞"><img class="comment-like-img comment-like-img-hover" style="display:none" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentActiveHeart.png" title="点赞"><img class="comment-like-img clickedImg" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentActiveHeart.png" title="点赞"><span>1</span></div></div></div></li></ul><ul class="comment-list"><li class="comment-line-box d-flex" data-commentid="15260512" data-replyname="WANTAWAY314"><div style="display: flex;width: 100%;">      <a target="_blank" href="https://blog.csdn.net/WANTAWAY314"><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/3_wantaway314" username="WANTAWAY314" alt="WANTAWAY314" class="avatar"></a>        <div class="right-box ">          <div class="new-info-box clearfix">            <a class="comment-tag" target="_blank" href="https://blog.csdn.net/blogdevteam/article/details/103478461">爱码士<img class="comment-tag-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentTagArrowWhite.png" title="爱码士"></a><a target="_blank" href="https://blog.csdn.net/WANTAWAY314"><span class="name ">water___Wang</span></a><span class="colon">:</span><span class="floor-num"></span><span class="new-comment">感谢分享</span><span class="date" title="2021-03-05 05:21:58">3 月前</span><span class="new-opt-floating"><a class="btn-bt  btn-reply" data-type="reply" data-flag="true">回复</a><a class="btn-bt  btn-report"><img class="btn-report-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentMore.png" title=""><span data-type="report" class="hide-report">举报</span></a></span></div><div class="comment-like " data-commentid="15260512"><img class="comment-like-img unclickImg" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentUnHeart.png" title="点赞"><img class="comment-like-img comment-like-img-hover" style="display:none" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentActiveHeart.png" title="点赞"><img class="comment-like-img clickedImg" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentActiveHeart.png" title="点赞"><span></span></div></div></div></li></ul><ul class="comment-list"><li class="comment-line-box d-flex" data-commentid="14187084" data-replyname="weixin_43423864"><div style="display: flex;width: 100%;">      <a target="_blank" href="https://blog.csdn.net/weixin_43423864"><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/3_weixin_43423864" username="weixin_43423864" alt="weixin_43423864" class="avatar"></a>        <div class="right-box ">          <div class="new-info-box clearfix">            <a class="comment-tag" target="_blank" href="https://blog.csdn.net/blogdevteam/article/details/103478461">码哥<img class="comment-tag-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentTagArrowWhite.png" title="码哥"></a><a target="_blank" href="https://blog.csdn.net/weixin_43423864"><span class="name ">一起码代码</span></a><span class="colon">:</span><span class="floor-num"></span><span class="new-comment">大佬写的太好了！</span><span class="date" title="2020-12-12 21:53:32">6 月前</span><span class="new-opt-floating"><a class="btn-bt  btn-reply" data-type="reply" data-flag="true">回复</a><a class="btn-bt  btn-report"><img class="btn-report-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentMore.png" title=""><span data-type="report" class="hide-report">举报</span></a></span></div><div class="comment-like " data-commentid="14187084"><img class="comment-like-img unclickImg" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentUnHeart.png" title="点赞"><img class="comment-like-img comment-like-img-hover" style="display:none" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentActiveHeart.png" title="点赞"><img class="comment-like-img clickedImg" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentActiveHeart.png" title="点赞"><span></span></div></div></div></li><li class="replay-box" style="display:block"><ul class="comment-list"><li class="comment-line-box d-flex" data-commentid="14188288" data-replyname="twj1248445531"><div style="display: flex;width: 100%;">      <a target="_blank" href="https://blog.csdn.net/twj1248445531"><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/3_twj1248445531" username="twj1248445531" alt="twj1248445531" class="avatar"></a>        <div class="right-box ">          <div class="new-info-box clearfix">            <a target="_blank" href="https://blog.csdn.net/twj1248445531"><span class="name mr-8">主旋律T<img class="is_bloger" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/bloger@2x.png"></span></a><span class="text">回复</span><span class="colon">:</span><span class="text"></span><span class="new-comment">大佬过奖了，我还只是个小白</span><span class="date" title="2020-12-13 00:32:32">6 月前</span><span class="new-opt-floating"><a class="btn-bt  btn-reply" data-type="reply" data-flag="true">回复</a><a class="btn-bt  btn-report"><img class="btn-report-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentMore.png" title=""><span data-type="report" class="hide-report">举报</span></a></span></div><div class="comment-like " data-commentid="14188288"><img class="comment-like-img unclickImg" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentUnHeart.png" title="点赞"><img class="comment-like-img comment-like-img-hover" style="display:none" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentActiveHeart.png" title="点赞"><img class="comment-like-img clickedImg" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/commentActiveHeart.png" title="点赞"><span></span></div></div></div></li></ul></li></ul></div>
		<div id="commentPage" class="pagination-box d-none" style="display: block;"><div id="Paging_003825876801772754" class="ui-paging-container"><ul><li class="js-page-first js-page-action ui-pager ui-pager-disabled"></li><li class="js-page-prev js-page-action ui-pager ui-pager-disabled">&lt;</li><li data-page="1" class="ui-pager focus">1</li><li class="js-page-next js-page-action ui-pager ui-pager-disabled">&gt;</li><li class="js-page-last js-page-action ui-pager ui-pager-disabled"></li></ul></div></div>
		
	</div>
</div>            <div class="recommend-tit-mod">相关推荐</div>
            <div class="recommend-box insert-baidu-box">
                <div class="recommend-item-box clearfix" style="display:none"></div><div class="recommend-item-box baiduSearch clearfix">	                <div class="content-box">		                <div class="content-blog display-flex">			                  <div class="title-box">				                  <a href="https://blog.csdn.net/Mrchongyang/article/details/83626080" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-0\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/Mrchongyang/article/details/83626080&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;0&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&amp;spm=1001.2101.3001.4242">					                <div class="tit ellipsis-online ellipsis-online-1"><em>java</em>.<em>UDP</em><em>通信</em>(<em>实现</em>服务端与<em>客户端</em>简单的聊天)_田重阳的...</div>				                  </a>			                  </div>                    <div class="info-box display-flex">                      <div class="info display-flex">                        <span class="info-block">6-17</span>                      </div>                    </div>                  </div>                  <div class="desc-box">                    <a href="https://blog.csdn.net/Mrchongyang/article/details/83626080" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-0\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/Mrchongyang/article/details/83626080&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;0&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&amp;spm=1001.2101.3001.4242">                      <div class="desc ellipsis-online ellipsis-online-1">编写两个<em>java</em><em>程序</em> 一个<em>程序</em>为服务端,建立<em>UDP</em>服务端套接字。 另外一个<em>程序</em>为<em>客户端</em>,建立<em>UDP</em><em>客户端</em>套接字。 这两个新<em>程序</em>可以互联,完成一个基于TCP/IP网络的文本聊天<em>程序</em>。 服务端<em>程序</em>: </div>                    </a>                  </div>                </div>              </div><div class="recommend-item-box baiduSearch clearfix">	                <div class="content-box">		                <div class="content-blog display-flex">			                  <div class="title-box">				                  <a href="https://blog.csdn.net/tomqq/article/details/17044465" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-1\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/tomqq/article/details/17044465&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;1&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-1&amp;spm=1001.2101.3001.4242">					                <div class="tit ellipsis-online ellipsis-online-1"><em>java</em>使用<em>UDP</em>来进行<em>客户端</em>和<em>服务器端</em><em>通信</em>的简单例子_tom...</div>				                  </a>			                  </div>                    <div class="info-box display-flex">                      <div class="info display-flex">                        <span class="info-block">6-15</span>                      </div>                    </div>                  </div>                  <div class="desc-box">                    <a href="https://blog.csdn.net/tomqq/article/details/17044465" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-1\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/tomqq/article/details/17044465&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;1&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-1&amp;spm=1001.2101.3001.4242">                      <div class="desc ellipsis-online ellipsis-online-1">packagecom.pb.<em>udp</em>; import<em>java</em>.io.IOException; import<em>java</em>.net.DatagramPacket; import<em>java</em>.net.InetAddress; import<em>java</em>.net.UnknownHostException; import<em>java</em>.net.Datagram<em>Socket</em>; /** * 使用Sender类来代表<em>客户端</em><em>程序</em>, ...</div>                    </a>                  </div>                </div>              </div>
<div class="recommend-item-box type_download clearfix" data-url="http://download.csdn.net/download/qq_39166617/10501484">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="http://download.csdn.net/download/qq_39166617/10501484" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-2.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;2&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;http://download.csdn.net/download/qq_39166617/10501484&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control">
					基于<em>Java</em><em>实现</em>de <em>UDP</em>数据传输，双向传输，接收端和发送端，服务器
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block">06-26</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="http://download.csdn.net/download/qq_39166617/10501484" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-2.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;2&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;http://download.csdn.net/download/qq_39166617/10501484&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control">
				<div class="desc ellipsis-online ellipsis-online-1"><em>UDP</em>是面向非连接的，<em>UDP</em>传输的是数据报只负责传输信息，不保证信息一定收到，虽然安全性不如TCP（面向连接、用<em>Socket</em>进行<em>通信</em>），但是性能较好。

从简单到复杂，首先简单介绍一下怎么利用<em>UDP</em><em>实现</em>客服端发送消息给<em>服务器端</em>吧：
发送、接受消息过程大概如下：

<em>服务器端</em>：创建Datagram<em>Socket</em>对象用于打开指定端口并监听，然后用创建一个DatagramPacket，利用Datagram<em>Socket</em>中的receive（ds）方法接收数据并放到刚创建的DatagramPacket对象中；
这样就完成了简单的发送，接收过程。

<em>客户端</em>：创建Datagram<em>Socket</em>对象，创建好IP地址和端口号后，利用Datagram<em>Socket</em>中的connect（ip,port）方法和服务端建立连接，然后利用Datagram<em>Socket</em>中的send（dp）方法发送早已准备好的数据。</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_download clearfix" data-url="http://download.csdn.net/download/yy228313/4879225">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="http://download.csdn.net/download/yy228313/4879225" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-3.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;3&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;http://download.csdn.net/download/yy228313/4879225&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.control">
					<em>java</em> 通过<em>UDP</em><em>实现</em>一对多聊天室
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block">12-12</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="http://download.csdn.net/download/yy228313/4879225" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-3.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;3&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;http://download.csdn.net/download/yy228313/4879225&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.control">
				<div class="desc ellipsis-online ellipsis-online-1">使用<em>java</em>通过<em>UDP</em><em>实现</em>一对多聊天室，而且有窗口</div>
			</a>
		</div>
	</div>
</div><div class="recommend-item-box baiduSearch clearfix">	                <div class="content-box">		                <div class="content-blog display-flex">			                  <div class="title-box">				                  <a href="https://blog.csdn.net/weixin_35965648/article/details/114146455" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-4\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_35965648/article/details/114146455&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;4&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-4&amp;spm=1001.2101.3001.4242">					                <div class="tit ellipsis-online ellipsis-online-1"><em>java</em><em>实现</em><em>udp</em>服务器_<em>Java</em><em>实现</em>单个<em>客户端</em>与服务器<em>UDP</em><em>通信</em>...</div>				                  </a>			                  </div>                    <div class="info-box display-flex">                      <div class="info display-flex">                        <span class="info-block">6-13</span>                      </div>                    </div>                  </div>                  <div class="desc-box">                    <a href="https://blog.csdn.net/weixin_35965648/article/details/114146455" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-4\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_35965648/article/details/114146455&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;4&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-4&amp;spm=1001.2101.3001.4242">                      <div class="desc ellipsis-online ellipsis-online-1">功能:<em>实现</em><em>UDP</em><em>通信</em>获取服务器的时间。 参考书:<em>Java</em> Network Programming(4th Edition) <em>UDP</em><em>客户端</em>: import <em>java</em>.io.IOException; import <em>java</em>.net.*; public class Client { //服务器开放端口 ...</div>                    </a>                  </div>                </div>              </div><div class="recommend-item-box baiduSearch clearfix">	                <div class="content-box">		                <div class="content-blog display-flex">			                  <div class="title-box">				                  <a href="https://blog.csdn.net/woshisap/article/details/6846656" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-5\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/woshisap/article/details/6846656&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;5&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-5&amp;spm=1001.2101.3001.4242">					                <div class="tit ellipsis-online ellipsis-online-1"><em>java</em>使用<em>UDP</em>来进行<em>客户端</em>和<em>服务器端</em><em>通信</em>的简单例子_张...</div>				                  </a>			                  </div>                    <div class="info-box display-flex">                      <div class="info display-flex">                        <span class="info-block">6-11</span>                      </div>                    </div>                  </div>                  <div class="desc-box">                    <a href="https://blog.csdn.net/woshisap/article/details/6846656" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-5\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/woshisap/article/details/6846656&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;5&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-5&amp;spm=1001.2101.3001.4242">                      <div class="desc ellipsis-online ellipsis-online-1">2:<em>服务器端</em><em>程序</em> packagecom.pb.<em>udp</em>; import<em>java</em>.io.IOException; import<em>java</em>.net.DatagramPacket; import<em>java</em>.net.Datagram<em>Socket</em>; import<em>java</em>.net.InetAddress; import<em>java</em>.net.<em>Socket</em>Address; ...</div>                    </a>                  </div>                </div>              </div>
		
<div class="recommend-item-box type_download clearfix" data-url="https://download.csdn.net/download/yunjian_luo153/9361191">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://download.csdn.net/download/yunjian_luo153/9361191" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-4.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;4&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/download/yunjian_luo153/9361191&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.control">
					采用<em>UDP</em>的<em>网络通信</em><em>客户端</em>（<em>Java</em><em>实现</em>）
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block">12-16</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://download.csdn.net/download/yunjian_luo153/9361191" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-4.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;4&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/download/yunjian_luo153/9361191&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.control">
				<div class="desc ellipsis-online ellipsis-online-1">这是本人用<em>Java</em>语言，采用<em>udp</em>协议<em>实现</em>的一个<em>网络通信</em><em>客户端</em>，一个<em>程序</em>你只需要打开两个端口，更改下端口号就可以<em>通信</em></div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/zylics/article/details/84046266">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/zylics/article/details/84046266" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-5.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;5&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zylics/article/details/84046266&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-5.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-5.control">
					<em>java</em>使用<em>UDP</em>来进行<em>客户端</em>和<em>服务器端</em><em>通信</em>的简单例子
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/zylics" target="_blank"><span class="blog-title">zylics的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">10-12</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					513
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/zylics/article/details/84046266" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-5.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;5&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zylics/article/details/84046266&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-5.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-5.control">
				<div class="desc ellipsis-online ellipsis-online-1">1：<em>客户端</em><em>程序</em>
view plain

    package com.pb.<em>udp</em>;  
      
    import <em>java</em>.io.IOException;  
    import <em>java</em>.net.DatagramPacket;  
    import <em>java</em>.net.InetAddress;  
    import <em>java</em>.net.UnknownHostE...</div>
			</a>
		</div>
	</div>
</div><div class="recommend-item-box baiduSearch clearfix">	                <div class="content-box">		                <div class="content-blog display-flex">			                  <div class="title-box">				                  <a href="https://blog.csdn.net/coobj2008/article/details/23105891" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-8\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/coobj2008/article/details/23105891&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;8&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-8&amp;spm=1001.2101.3001.4242">					                <div class="tit ellipsis-online ellipsis-online-1"><em>Java</em><em>实现</em>单个<em>客户端</em>与服务器<em>UDP</em><em>通信</em>_coobj2008的专栏</div>				                  </a>			                  </div>                    <div class="info-box display-flex">                      <div class="info display-flex">                        <span class="info-block">5-13</span>                      </div>                    </div>                  </div>                  <div class="desc-box">                    <a href="https://blog.csdn.net/coobj2008/article/details/23105891" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-baidujs_title-8\&quot;}&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4242&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/coobj2008/article/details/23105891&quot;,&quot;strategy&quot;:&quot;baidujs_title&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;index&quot;:&quot;8&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-8&amp;spm=1001.2101.3001.4242">                      <div class="desc ellipsis-online ellipsis-online-1">功能:<em>实现</em><em>UDP</em><em>通信</em>获取服务器的时间。 参考书:<em>Java</em> Network Programming(4th Edition) <em>UDP</em><em>客户端</em>: import<em>java</em>.io.IOException; import<em>java</em>.net.*; publicclassClient{ //服务器开放端口 publicstaticfinalintPORT =3000; ...</div>                    </a>                  </div>                </div>              </div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/gang148375/article/details/90245689">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/gang148375/article/details/90245689" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-6.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;6&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/gang148375/article/details/90245689&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control">
					<em>Java</em>的<em>UDP</em>服务端
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/gang148375" target="_blank"><span class="blog-title">gang148375的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">05-15</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					1779
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/gang148375/article/details/90245689" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-6.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;6&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/gang148375/article/details/90245689&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control">
				<div class="desc ellipsis-online ellipsis-online-1">本文主要是讲<em>Java</em>的<em>UDP</em>服务端接收<em>客户端</em>消息的<em>实现</em>过程

package com.Demo;

import <em>java</em>.io.IOException;
import <em>java</em>.net.DatagramPacket;
import <em>java</em>.net.Datagram<em>Socket</em>;
import <em>java</em>.net.InetAddress;
import <em>java</em>.net.<em>Socket</em>Excepti...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_download clearfix" data-url="https://download.csdn.net/download/qq_37040173/11290916">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://download.csdn.net/download/qq_37040173/11290916" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromBaidu~default-7.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;7&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/download/qq_37040173/11290916&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-7.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-7.control">
					基于<em>UDP</em>传输控制协议和GUI开发的聊天窗口<em>程序</em>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block">07-06</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://download.csdn.net/download/qq_37040173/11290916" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromBaidu~default-7.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;7&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/download/qq_37040173/11290916&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-7.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-7.control">
				<div class="desc ellipsis-online ellipsis-online-1">基于<em>UDP</em>传输控制协议和GUI开发的聊天窗口<em>程序</em>，可以启动多次main<em>程序</em>，<em>实现</em>一个IP地址，多个监听口。有聊天窗口，方便使用</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/codes_first/article/details/78385857">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/codes_first/article/details/78385857" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-8.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;8&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/codes_first/article/details/78385857&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.control">
					<em>java</em>使用<em>UDP</em>协议进行服务器<em>客户端</em><em>通信</em>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/codes_first" target="_blank"><span class="blog-title">codes_first的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">10-29</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					4933
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/codes_first/article/details/78385857" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-8.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;8&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/codes_first/article/details/78385857&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.control">
				<div class="desc ellipsis-online ellipsis-online-1">先唠叨一些基础东西：1、两台计算机间进行通讯需要以下三个条件：
IP地址、协议、端口号2、IP地址、端口
为<em>实现</em>网络中不同计算机之间的<em>通信</em>，每台计算机都必须有一个唯一的标识---IP地址。而区分一台主机的多个不同应用<em>程序</em>，则是用端口标识，端口号范围为0-65535，其中0-1023位为系统保留。IP地址+端口号组成了所谓的<em>Socket</em>。 3、<em>Socket</em>套接字：
网络上具有唯一标识的IP地址和端口组</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/qq_30843221/article/details/49127037">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/qq_30843221/article/details/49127037" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-9.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;9&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/qq_30843221/article/details/49127037&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.control">
					关于<em>Java</em>的<em>UDP</em><em>通信</em>连接<em>实现</em>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/qq_30843221" target="_blank"><span class="blog-title">qq_30843221的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">10-14</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					8597
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/qq_30843221/article/details/49127037" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-9.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;9&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/qq_30843221/article/details/49127037&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.control">
				<div class="desc ellipsis-online ellipsis-online-1">知识点：1.关于TCP与<em>UDP</em>的主要区别： 
        TCP—传输控制协议,提供的是面向连接、可靠的字节流服务。当客户和服务器彼此交换数据前，必须先在双方之间建立一个TCP连接，之后才能传输数据。TCP提供超时重发，丢弃重复数据，检验数据，流量控制等功能，保证数据能从一端传到另一端。 
        <em>UDP</em>—用户数据报协议，是一个简单的面向数据报的运输层协议。<em>UDP</em>不提供可靠性，它只是把应</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://later.blog.csdn.net/article/details/80543774">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://later.blog.csdn.net/article/details/80543774" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-10.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;10&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://later.blog.csdn.net/article/details/80543774&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.control">
					<em>java</em> 简单地<em>udp</em>服务器----云平台开发学习笔记
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/qq_37832932" target="_blank"><span class="blog-title">later的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">06-01</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					7973
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://later.blog.csdn.net/article/details/80543774" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-10.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;10&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://later.blog.csdn.net/article/details/80543774&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.control">
				<div class="desc ellipsis-online ellipsis-online-1">应用: 在选择使用协议的时候，选择<em>UDP</em>必须要谨慎。在网络质量令人十分不满意的环境下，<em>UDP</em>协议数据包丢失会比较严重。但是由于<em>UDP</em>的特性：它不属于连接型协议，因而具有资源消耗小，处理速度快的优点，所以通常音频、视频和普通数据在传送时使用<em>UDP</em>较多，因为它们即使偶尔丢失一两个数据包，也不会对接收结果产生太大影响。比如我们聊天用的ICQ和QQ就是使用的<em>UDP</em>协议。<em>java</em>开发: <em>java</em>中的<em>UDP</em>实...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/yaerfeng/article/details/53780627">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/yaerfeng/article/details/53780627" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-11.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;11&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/yaerfeng/article/details/53780627&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-11.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-11.control">
					<em>java</em> <em>udp</em>网络编程及实例代码，<em>实现</em><em>客户端</em>和服务端<em>通信</em>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/yaerfeng" target="_blank"><span class="blog-title">云淡风轻、仅此一抹</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">12-21</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					2652
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/yaerfeng/article/details/53780627" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-11.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;11&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/yaerfeng/article/details/53780627&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-11.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-11.control">
				<div class="desc ellipsis-online ellipsis-online-1">原文：<em>java</em>
 <em>udp</em>网络编程及实例代码，<em>实现</em><em>客户端</em>和服务端<em>通信</em>

源代码下载地址：http://www.zuidaima.com/share/1891270130977792.htm
<em>java</em> <em>udp</em>网络编程及实例代码，<em>实现</em><em>客户端</em>和服务端<em>通信</em>
有图有真相了！</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_42297444/article/details/114358638">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_42297444/article/details/114358638" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-12.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;12&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_42297444/article/details/114358638&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-12.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-12.control">
					ios <em>udp</em> <em>java</em>服务器_<em>Java</em><em>实现</em><em>简易</em><em>UDP</em><em>客户端</em>、<em>服务器端</em><em>通信</em><em>程序</em>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_42297444" target="_blank"><span class="blog-title">weixin_42297444的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">02-19</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					9
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_42297444/article/details/114358638" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-12.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;12&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_42297444/article/details/114358638&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-12.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-12.control">
				<div class="desc ellipsis-online ellipsis-online-1">本学期<em>计算机网络</em>课程要求完成一个TCP和一个<em>UDP</em>的<em>通信</em><em>程序</em>，我完成了功能的简单<em>实现</em>。我在上一篇博客已经讲了TCP的具体<em>实现</em>，接下来讲一讲<em>UDP</em><em>程序</em>的<em>实现</em>。效果展示初始界面连接成功互发消息以下是具体<em>实现</em>过程：一、项目结构项目结构下面说说每个类的具体作用：<em>UDP</em>Client：<em>UDP</em><em>客户端</em>的核心代码部分；<em>UDP</em>Server：<em>UDP</em><em>服务器端</em>的核心代码部分;<em>UDP</em>Frame：<em>UDP</em><em>客户端</em>和<em>服务器端</em>的界面搭...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_download clearfix" data-url="https://download.csdn.net/download/weixin_38669628/11531469">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://download.csdn.net/download/weixin_38669628/11531469" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-13.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;13&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/download/weixin_38669628/11531469&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-13.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-13.control">
					<em>java</em> -&gt; <em>UDP</em> Server/Client
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block">08-13</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://download.csdn.net/download/weixin_38669628/11531469" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromMachineLearnPai2~default-13.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;13&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://download.csdn.net/download/weixin_38669628/11531469&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-13.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-13.control">
				<div class="desc ellipsis-online ellipsis-online-1">NULL
博文链接：https://mft.iteye.com/blog/2306841</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/twj1248445531/article/details/110947510">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/twj1248445531/article/details/110947510" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-14.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;14&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/110947510&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-14.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-14.control">
					<em>Java</em><em>实现</em><em>简易</em>TCP<em>客户端</em>、<em>服务器端</em><em>通信</em><em>程序</em>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/twj1248445531" target="_blank"><span class="blog-title">twj1248445531的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">12-10</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					294
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/twj1248445531/article/details/110947510" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-14.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;14&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/110947510&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-14.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-14.control">
				<div class="desc ellipsis-online ellipsis-online-1">本学期<em>计算机网络</em>课程要求完成一个TCP和一个<em>UDP</em>的<em>通信</em><em>程序</em>，我完成了功能的简单<em>实现</em>，下面讲讲我的TCP<em>程序</em>的<em>实现</em>。

目录效果展示一、项目结构二、完整代码1.TCPClient1.TCPClient总结

效果展示


以下是具体<em>实现</em>过程：
一、项目结构


下面说说每个类的具体作用：
TCPClient：TCP<em>客户端</em>的核心代码部分；
TCPClientFrame：TCP<em>客户端</em>的界面搭建；
TCPServer：TCP<em>服务器端</em>的核心代码部分；
TCPServerFrame：TCP<em>服务器端</em>的界面搭建；
TCP</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_other clearfix" data-url="https://plugin.csdn.net/?from=blog_detail">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://plugin.csdn.net/?from=blog_detail" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.541115.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;15&quot;,&quot;style&quot;:&quot;text_1&quot;,&quot;strategy&quot;:&quot;11_541115_RCMD&quot;,&quot;dest&quot;:&quot;https://plugin.csdn.net/?from=blog_detail&quot;}" data-report-query="utm_medium=distribute.pc_relevant.541115.control&amp;depth_1-utm_source=distribute.pc_relevant.541115.control">
					CSDN开发者助手，常用网站自动整合，多种工具一键调用
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block"></span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://plugin.csdn.net/?from=blog_detail" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.541115.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;15&quot;,&quot;style&quot;:&quot;text_1&quot;,&quot;strategy&quot;:&quot;11_541115_RCMD&quot;,&quot;dest&quot;:&quot;https://plugin.csdn.net/?from=blog_detail&quot;}" data-report-query="utm_medium=distribute.pc_relevant.541115.control&amp;depth_1-utm_source=distribute.pc_relevant.541115.control">
				<div class="desc ellipsis-online ellipsis-online-1">CSDN开发者助手由CSDN官方开发，集成一键呼出搜索、万能快捷工具、个性化新标签页和官方免广告四大功能。帮助您提升10倍开发效率！</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_30514427/article/details/114058014">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_30514427/article/details/114058014" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-16.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;16&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_30514427/article/details/114058014&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-16.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-16.control">
					<em>udp</em><em>客户端</em> <em>Java</em>_<em>java</em>使用<em>UDP</em>来进行<em>客户端</em>和<em>服务器端</em><em>通信</em>的简单例子 | 学步园
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_30514427" target="_blank"><span class="blog-title">weixin_30514427的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">02-12</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					19
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_30514427/article/details/114058014" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromMachineLearnPai2~default-16.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;16&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromMachineLearnPai2~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_30514427/article/details/114058014&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-16.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-16.control">
				<div class="desc ellipsis-online ellipsis-online-1">1：<em>客户端</em><em>程序</em>package com.pb.<em>udp</em>;import <em>java</em>.io.IOException;import <em>java</em>.net.DatagramPacket;import <em>java</em>.net.InetAddress;import <em>java</em>.net.UnknownHostException;import <em>java</em>.net.Datagram<em>Socket</em>;/***  使用Sender类来代表客户...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_download clearfix" data-url="http://download.csdn.net/download/weixin_38703895/12743772">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="http://download.csdn.net/download/weixin_38703895/12743772" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromBaidu~default-17.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;17&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;http://download.csdn.net/download/weixin_38703895/12743772&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.control">
					<em>java</em> <em>UDP</em><em>通信</em><em>客户端</em>与<em>服务器端</em>实例分析
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block">08-25</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="http://download.csdn.net/download/weixin_38703895/12743772" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-download-2~default~BlogCommendFromBaidu~default-17.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;17&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;http://download.csdn.net/download/weixin_38703895/12743772&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.control">
				<div class="desc ellipsis-online ellipsis-online-1">主要介绍了<em>java</em> <em>UDP</em><em>通信</em><em>客户端</em>与<em>服务器端</em>,结合实例形式分析了<em>java</em>基于<em>UDP</em><em>通信</em>的<em>客户端</em>与<em>服务器端</em>具体<em>实现</em>技巧及相关操作注意事项,需要的朋友可以参考下</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_33268492/article/details/114065755">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_33268492/article/details/114065755" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-18.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;18&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_33268492/article/details/114065755&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-18.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-18.control">
					<em>java</em> <em>udp</em><em>客户端</em>_<em>java</em> <em>UDP</em> <em>通信</em>:服务端与客服端
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_33268492" target="_blank"><span class="blog-title">weixin_33268492的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">02-12</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					30
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_33268492/article/details/114065755" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-18.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;18&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_33268492/article/details/114065755&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-18.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-18.control">
				<div class="desc ellipsis-online ellipsis-online-1">没有多线程import <em>java</em>.io.IOException;import <em>java</em>.net.DatagramPacket;import <em>java</em>.net.Datagram<em>Socket</em>;import <em>java</em>.net.InetAddress;import <em>java</em>.net.<em>Socket</em>Exception;import <em>java</em>.net.UnknownHostException;import ja...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_29962473/article/details/114058011">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_29962473/article/details/114058011" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-19.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;19&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_29962473/article/details/114058011&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-19.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-19.control">
					<em>udp</em><em>客户端</em> <em>Java</em>_<em>java</em> <em>UDP</em><em>通信</em><em>客户端</em>与<em>服务器端</em>实例分析
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_29962473" target="_blank"><span class="blog-title">weixin_29962473的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">02-12</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					9
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_29962473/article/details/114058011" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-19.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;19&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_29962473/article/details/114058011&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-19.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-19.control">
				<div class="desc ellipsis-online ellipsis-online-1">本文实例讲述了<em>java</em> <em>UDP</em><em>通信</em><em>客户端</em>与<em>服务器端</em>。分享给大家供大家参考，具体如下：最初<em>Udp</em>是以字节为单位进行传输的，所以有很大的限制<em>服务器端</em>：import <em>java</em>.net.*;public class Test<em>Udp</em>Server {public static void main(String[] args) throws Exception {byte[] buf = new byte[10...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_42882887/article/details/86598410">
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_42882887/article/details/86598410" class="tit ellipsis-online ellipsis-online-1" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-20.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;20&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_42882887/article/details/86598410&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-20.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-20.control">
					<em>Java</em><em>实现</em><em>UDP</em><em>通信</em>过程
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_42882887" target="_blank"><span class="blog-title">Juily家的小蜜果</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">01-22</span>
					<span class="info-block read"><img class="read-img" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					1万+
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_42882887/article/details/86598410" target="_blank" data-report-click="{&quot;ab&quot;:&quot;new&quot;,&quot;mod&quot;:&quot;popu_387&quot;,&quot;extra&quot;:&quot;{\&quot;utm_medium\&quot;:\&quot;distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-20.control\&quot;}&quot;,&quot;dist_request_id&quot;:&quot;1624496559237_43588&quot;,&quot;index&quot;:&quot;20&quot;,&quot;strategy&quot;:&quot;2~default~BlogCommendFromBaidu~default&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/weixin_42882887/article/details/86598410&quot;}" data-report-query="utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-20.control&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-20.control">
				<div class="desc ellipsis-online ellipsis-online-1">TCP是一种面向连接的传输层协议，而<em>UDP</em>是传输层中面向无连接的协议，故传送的数据包不能保证有序和不丢失，<em>实现</em><em>UDP</em><em>通信</em>主要用到了两个类：DatagramPacket和Datagram<em>Socket</em>。
Datagram<em>Socket</em>
这个类用来表示发送和接收数据包的套接字。
//构造方法，创建数据报套接字并将其绑定到本地主机上的指定端口
Datagram<em>Socket</em> <em>socket</em> = new Data...</div>
			</a>
		</div>
	</div>
</div>
            </div>
            <div class="template-box">
                <span>©️2020 CSDN</span>
                <span>皮肤主题: 深蓝海洋</span>
                <span> 设计师:CSDN官方博客</span>
                <span>
                    <a href="https://blog.csdn.net/" class="back-home c-blue c-blue-hover c-blue-focus">返回首页</a>
                </span>
            </div>
<div class="blog-footer-bottom" style="margin-top:10px;">
        <div id="copyright-box" class="">
          <div id="csdn-copyright-footer" class="column small">
            <ul class="footer-column-t">
            <li>
              <a href="https://www.csdn.net/company/index.html#about" target="_blank">关于我们</a>
            </li>
            <li>
              <a href="https://www.csdn.net/company/index.html#recruit" target="_blank">招贤纳士</a>
            </li>
            <li>
              <a href="https://www.csdn.net/company/index.html#advertisement" target="_blank">广告服务</a>
            </li>
            <li>
              <a href="https://plugin.csdn.net/" target="_blank">开发助手</a>
            </li>
            <li>
              <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/tel.png" alt="">
              <span>400-660-0108</span>
            </li>
            <li>
              <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/email.png" alt="">
              <a href="mailto:webmaster@csdn.net" target="_blank">kefu@csdn.net</a>
            </li>
            <li>
              <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/cs.png" alt="">
              <a href="https://csdn.s2.udesk.cn/im_client/?web_plugin_id=29181" target="_blank">在线客服</a>
            </li>
            <li>
              工作时间&nbsp;8:30-22:00
            </li>
          </ul>
            <ul class="footer-column-b">
            <li><img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/badge.png" alt=""><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010502030143" rel="noreferrer" target="_blank">公安备案号11010502030143</a></li>
            <li><a href="http://beian.miit.gov.cn/publish/query/indexFirst.action" rel="noreferrer" target="_blank">京ICP备19004658号</a></li>
            <li><a href="https://csdnimg.cn/release/live_fe/culture_license.png" rel="noreferrer" target="_blank">京网文〔2020〕1039-165号</a></li>
            <li><a href="https://csdnimg.cn/cdn/content-toolbar/csdn-ICP.png" target="_blank">经营性网站备案信息</a></li>
            <li><a href="http://www.bjjubao.org/" target="_blank">北京互联网违法和不良信息举报中心</a></li>
            <li><a href="http://www.cyberpolice.cn/" target="_blank">网络110报警服务</a></li>
            <li><a href="http://www.12377.cn/" target="_blank">中国互联网举报中心</a></li>
            <li><a href="https://download.csdn.net/index.php/tutelage/" target="_blank">家长监护</a></li>
            <li><a href="https://chrome.google.com/webstore/detail/csdn%E5%BC%80%E5%8F%91%E8%80%85%E5%8A%A9%E6%89%8B/kfkdboecolemdjodhmhmcibjocfopejo?hl=zh-CN" target="_blank">Chrome商店下载</a></li>
            <li>©1999-2021北京创新乐知网络技术有限公司</li>
            <li><a href="https://www.csdn.net/company/index.html#statement" target="_blank">版权与免责声明</a></li>
            <li><a href="https://blog.csdn.net/blogdevteam/article/details/90369522" target="_blank">版权申诉</a></li>
            <li><a href="https://img-home.csdnimg.cn/images/20210414021151.jpg" target="_blank">出版物许可证</a></li>
            <li><a href="https://img-home.csdnimg.cn/images/20210414021142.jpg" target="_blank">营业执照</a></li>
          </ul>
          </div>
        </div>
      </div>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/csdn-footer.js" data-isfootertrack="false" type="text/javascript"></script>
<script type="text/javascript">
    window.csdn.csdnFooter.options = {
        el: '.blog-footer-bottom',
        type: 2
    }
</script>        </main>
<aside class="blog_container_aside">
	<div id="asideProfile" class="aside-box">
    <div class="profile-intro d-flex">
        <div class="avatar-box d-flex justify-content-center flex-column">
            <a href="https://blog.csdn.net/twj1248445531" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4121&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531&quot;,&quot;ab&quot;:&quot;new&quot;}">
                <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/3_twj1248445531" class="avatar_pic">
            </a>
        </div>
        <div class="user-info d-flex flex-column profile-intro-name-box">
            <div class="profile-intro-name-boxTop">
                <a href="https://blog.csdn.net/twj1248445531" class="" id="uid" title="主旋律T" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4122&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531&quot;,&quot;ab&quot;:&quot;new&quot;}">
                    <span class="name " username="twj1248445531">主旋律T</span>
                </a>
                <span>
                </span>
                <span class="flag expert-blog">
                <span class="bubble">CSDN认证博客专家</span>
                </span>
                <span class="flag company-blog">
                <span class="bubble">CSDN认证企业博客</span>
                </span>
            </div>
            <div class="profile-intro-name-boxFooter">
                <span class="personal-home-page personal-home-years">码龄1年</span>
                    <span class="personal-home-page">
                    <a class="personal-home-certification" href="https://i.csdn.net/#/uc/profile?utm_source=14998968" target="_blank" title="暂无认证">
                    <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/nocErtification.png" alt="">
                    暂无认证
                    </a>
                    </span>
            </div>
        </div>
    </div>
    <div class="data-info d-flex item-tiling">
        <dl class="text-center" title="7">
            <a href="https://blog.csdn.net/twj1248445531" data-report-click="{&quot;mod&quot;:&quot;1598321000_001&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4310&quot;}" data-report-query="t=1">  
                <dt><span class="count">7</span></dt>
                <dd class="font">原创</dd>
            </a>
        </dl>
        <dl class="text-center" data-report-click="{&quot;mod&quot;:&quot;1598321000_002&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4311&quot;}" title="205297">
            <a href="https://blog.csdn.net/rank/list/weekly" target="_blank">
                <dt><span class="count">20万+</span></dt>
                <dd class="font">周排名</dd>
            </a>
        </dl>
        <dl class="text-center" title="592788">
            <a href="https://blog.csdn.net/rank/list/total" data-report-click="{&quot;mod&quot;:&quot;1598321000_003&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4312&quot;}" target="_blank">
                <dt><span class="count">59万+</span></dt>
                <dd class="font">总排名</dd>
            </a>
        </dl>
        <dl class="text-center" style="min-width:58px" title="1851">  
            <dt><span class="count">1851</span></dt>
            <dd>访问</dd>
        </dl>
        <dl class="text-center" title="1级,点击查看等级说明">
            <dt><a href="https://blog.csdn.net/blogdevteam/article/details/103478461" target="_blank">
                <img class="level" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/blog1.png">
            </a>
            </dt>
            <dd>等级</dd>
        </dl>
    </div>
    <div class="item-rank"></div>
    <div class="data-info d-flex item-tiling">
        <dl class="text-center" title="97">
            <dt><span class="count">97</span></dt>
            <dd>积分</dd>
        </dl>
         <dl class="text-center" id="fanBox" title="4">
            <dt><span class="count" id="fan">4</span></dt>
            <dd>粉丝</dd>
        </dl>
        <dl class="text-center" title="16">
            <dt><span class="count">16</span></dt>
            <dd>获赞</dd>
        </dl>
        <dl class="text-center" title="11">
            <dt><span class="count">11</span></dt>
            <dd>评论</dd>
        </dl>
        <dl class="text-center" title="18">
            <dt><span class="count">18</span></dt>
            <dd>收藏</dd>
        </dl>
    </div>
    <div class="aside-box-footer">
        <div class="badge-box d-flex">
            <div class="badge d-flex">
                <div class="icon-badge" title="新秀勋章">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click="{&quot;spm&quot;:&quot;3001.4296&quot;}" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/xinxiu@240.png" alt="新秀勋章">
                    </div>
                </div>
                <div class="icon-badge" title="持之以恒">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click="{&quot;spm&quot;:&quot;3001.4296&quot;}" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/chizhiyiheng@240.png" alt="持之以恒">
                    </div>
                </div>
                <div class="icon-badge" title="勤写标兵Lv2">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click="{&quot;spm&quot;:&quot;3001.4296&quot;}" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/qixiebiaobing2@240.png" alt="勤写标兵Lv2">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="profile-intro-name-boxOpration">
        <div class="opt-letter-watch-box">
        <a class="bt-button personal-letter" href="https://im.csdn.net/chat/twj1248445531" target="_blank" rel="noopener">私信</a>
        </div>
        <div class="opt-letter-watch-box"> 
            <a class="personal-watch bt-button" id="btnAttent">关注</a>  
        </div>
    </div>
</div>
<div id="asideSearchArticle" class="aside-box">
	<div class="aside-content search-comter">
    <div class="aside-search aside-search-blog">         
        <input type="text" class="input-serch-blog" name="" autocomplete="off" value="" id="search-blog-words" placeholder="搜博主文章">
        <a class="btn-search-blog">
                    <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/csdn-sou.png">
        </a>
    </div>
    </div>
</div>


<div id="asideHotArticle" class="aside-box">
	<h3 class="aside-title">热门文章</h3>
	<div class="aside-content">
		<ul class="hotArticle-list">
			<li>
				<a href="https://blog.csdn.net/twj1248445531/article/details/110926300" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_541&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4139&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/110926300&quot;,&quot;ab&quot;:&quot;new&quot;}">
				Java实现抓包程序（网络协议分析程序）
					<img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					<span class="read">757</span>
                </a>
			</li>
			<li>
				<a href="https://blog.csdn.net/twj1248445531/article/details/111032255" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_541&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4139&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/111032255&quot;,&quot;ab&quot;:&quot;new&quot;}">
				Java实现简易UDP客户端、服务器端通信程序
					<img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					<span class="read">393</span>
                </a>
			</li>
			<li>
				<a href="https://blog.csdn.net/twj1248445531/article/details/110947510" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_541&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4139&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/110947510&quot;,&quot;ab&quot;:&quot;new&quot;}">
				Java实现简易TCP客户端、服务器端通信程序
					<img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					<span class="read">294</span>
                </a>
			</li>
			<li>
				<a href="https://blog.csdn.net/twj1248445531/article/details/111355287" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_541&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4139&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/111355287&quot;,&quot;ab&quot;:&quot;new&quot;}">
				Bootstrap(Web框架)的简单使用教程
					<img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					<span class="read">114</span>
                </a>
			</li>
			<li>
				<a href="https://blog.csdn.net/twj1248445531/article/details/110918698" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_541&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4139&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/110918698&quot;,&quot;ab&quot;:&quot;new&quot;}">
				JavaScript基础入门知识
					<img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/readCountWhite.png" alt="">
					<span class="read">72</span>
                </a>
			</li>
		</ul>
	</div>
</div>
<div id="asideCategory" class="aside-box ">
    <h3 class="aside-title">分类专栏</h3>
    <div class="aside-content">
        <ul>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/twj1248445531/category_11051269.html" data-report-click="{&quot;mod&quot;:&quot;popu_537&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4137&quot;,&quot;strategy&quot;:&quot;pc付费专栏左侧入口&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/category_11051269.html&quot;,&quot;ab&quot;:&quot;new&quot;}">
                    <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201014180756928.png" alt="" onerror="this.src=&#39;https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64&#39;">
                    <span class="title oneline">
                        <span class="text">课程笔记</span>
                    </span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/twj1248445531/category_10913600.html" data-report-click="{&quot;mod&quot;:&quot;popu_537&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4137&quot;,&quot;strategy&quot;:&quot;pc付费专栏左侧入口&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/category_10913600.html&quot;,&quot;ab&quot;:&quot;new&quot;}">
                    <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201014180756922.png" alt="" onerror="this.src=&#39;https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64&#39;">
                    <span class="title oneline">
                        <span class="text">项目异常</span>
                    </span>
                    <span class="count float-right">1篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/twj1248445531/category_10647469.html" data-report-click="{&quot;mod&quot;:&quot;popu_537&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4137&quot;,&quot;strategy&quot;:&quot;pc付费专栏左侧入口&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/category_10647469.html&quot;,&quot;ab&quot;:&quot;new&quot;}">
                    <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201014180756928.png" alt="" onerror="this.src=&#39;https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64&#39;">
                    <span class="title oneline">
                        <span class="text">html学习</span>
                    </span>
                    <span class="count float-right">3篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/twj1248445531/category_10647981.html" data-report-click="{&quot;mod&quot;:&quot;popu_537&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4137&quot;,&quot;strategy&quot;:&quot;pc付费专栏左侧入口&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/category_10647981.html&quot;,&quot;ab&quot;:&quot;new&quot;}">
                    <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201014180756928.png" alt="" onerror="this.src=&#39;https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64&#39;">
                    <span class="title oneline">
                        <span class="text">计算机网络小项目</span>
                    </span>
                    <span class="count float-right">3篇</span>
                </a>
            </li>
        </ul>
    </div>
</div>
<div id="asideNewComments" class="aside-box">
    <h3 class="aside-title">最新评论</h3>
    <div class="aside-content">
        <ul class="newcomment-list">
            <li>
                <a class="title text-truncate" target="_blank" href="https://blog.csdn.net/twj1248445531/article/details/110926300#comments_15672726" data-report-click="{&quot;mod&quot;:&quot;popu_542&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4231&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/110926300#comments_15672726&quot;,&quot;ab&quot;:&quot;new&quot;}">Java实现抓包程序（网络协议分析程序）</a>
                <p class="comment ellipsis">
                    <a href="https://blog.csdn.net/twj1248445531" class="user-name" target="_blank">主旋律T: </a>
                    <span class="code-comments">代码已上传到GitHub，链接：https://github.com/1248445531/packetCapture</span>
                </p>
            </li>
            <li>
                <a class="title text-truncate" target="_blank" href="https://blog.csdn.net/twj1248445531/article/details/111032255#comments_15260512" data-report-click="{&quot;mod&quot;:&quot;popu_542&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4231&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/111032255#comments_15260512&quot;,&quot;ab&quot;:&quot;new&quot;}">Java实现简易UDP客户端、服务器端通信程序</a>
                <p class="comment ellipsis">
                    <a href="https://waterwang.blog.csdn.net/" class="user-name" target="_blank">water___Wang: </a>
                    <span class="code-comments">感谢分享</span>
                </p>
            </li>
            <li>
                <a class="title text-truncate" target="_blank" href="https://blog.csdn.net/twj1248445531/article/details/111355287#comments_14284620" data-report-click="{&quot;mod&quot;:&quot;popu_542&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4231&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/111355287#comments_14284620&quot;,&quot;ab&quot;:&quot;new&quot;}">Bootstrap(Web框架)的简单使用教程</a>
                <p class="comment ellipsis">
                    <a href="https://blog.csdn.net/kimol_justdo" class="user-name" target="_blank">不正经的kimol君: </a>
                    <span class="code-comments">大佬，我准备跟你混了！</span>
                </p>
            </li>
            <li>
                <a class="title text-truncate" target="_blank" href="https://blog.csdn.net/twj1248445531/article/details/111032255#comments_14196479" data-report-click="{&quot;mod&quot;:&quot;popu_542&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4231&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/111032255#comments_14196479&quot;,&quot;ab&quot;:&quot;new&quot;}">Java实现简易UDP客户端、服务器端通信程序</a>
                <p class="comment ellipsis">
                    <a href="https://blog.csdn.net/kimol_justdo" class="user-name" target="_blank">不正经的kimol君: </a>
                    <span class="code-comments">学到了，点赞支持</span>
                </p>
            </li>
            <li>
                <a class="title text-truncate" target="_blank" href="https://blog.csdn.net/twj1248445531/article/details/111032255#comments_14188288" data-report-click="{&quot;mod&quot;:&quot;popu_542&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4231&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/111032255#comments_14188288&quot;,&quot;ab&quot;:&quot;new&quot;}">Java实现简易UDP客户端、服务器端通信程序</a>
                <p class="comment ellipsis">
                    <a href="https://blog.csdn.net/twj1248445531" class="user-name" target="_blank">主旋律T: </a>
                    <span class="code-comments">大佬过奖了，我还只是个小白</span>
                </p>
            </li>
        </ul>
    </div>
</div>
<div id="asideArchive" class="aside-box" style="display:block!important; width:300px;">
    <h3 class="aside-title">最新文章</h3>
    <div class="aside-content">
        <ul class="inf_list clearfix">
            <li class="clearfix">
            <a href="https://blog.csdn.net/twj1248445531/article/details/115174889" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_382&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4136&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/115174889&quot;,&quot;ab&quot;:&quot;new&quot;}">工厂模式解耦时抛出异常java.lang.ClassNotFoundException</a>
            </li>
            <li class="clearfix">
            <a href="https://blog.csdn.net/twj1248445531/article/details/114736734" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_382&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4136&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/114736734&quot;,&quot;ab&quot;:&quot;new&quot;}">jQuery中append、prepend等的用法与记忆</a>
            </li>
            <li class="clearfix">
            <a href="https://blog.csdn.net/twj1248445531/article/details/111355287" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_382&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4136&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/article/details/111355287&quot;,&quot;ab&quot;:&quot;new&quot;}">Bootstrap(Web框架)的简单使用教程</a>
            </li>
        </ul>
        <div class="archive-bar"></div>
        <div class="archive-box">
                <div class="archive-list-item"><a href="https://blog.csdn.net/twj1248445531/article/month/2021/03" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_538&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4138&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;dest&quot;:&quot;&quot;}"><span class="year">2021年</span><span class="num">2篇</span></a></div>
                <div class="archive-list-item"><a href="https://blog.csdn.net/twj1248445531/article/month/2020/12" target="_blank" data-report-click="{&quot;mod&quot;:&quot;popu_538&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4138&quot;,&quot;ab&quot;:&quot;new&quot;,&quot;dest&quot;:&quot;&quot;}"><span class="year">2020年</span><span class="num">5篇</span></a></div>
        </div>
    </div>
</div>
	<div id="footerRightAds" class="isShowFooterAds">
		<div class="aside-box">
			<div id="kp_box_57" data-pid="57"><iframe src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/saved_resource(4).html" frameborder="0" width="300px" height="600px" scrolling="no"></iframe><img class="pre-img-lasy" data-src="https://kunyu.csdn.net/1.png?p=57&amp;a=4313&amp;c=7542&amp;k=&amp;spm=1001.2101.3001.5001&amp;d=1&amp;t=3&amp;u=be99debb2fd54ef5b6da22a05685c80b" style="display: block;width: 0px;height: 0px;" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/1(1).png"></div>
		</div>
	</div>
    <!-- 详情页显示目录 -->
<!--文章目录-->
<div id="asidedirectory" class="aside-box">
    <div class="groupfile" id="directory">
        <h3 class="aside-title">目录</h3>
        <div class="align-items-stretch group_item">
            <div class="pos-box">
            <div class="scroll-box">
                <div class="toc-box"><ol><li class="active"><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t0">目录</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t1">效果展示</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t2">一、项目结构</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t3">二、完整代码</a></li><li class="sub-box"><ol><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t4">1.UDPClient</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t5">2.UDPServer</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t6">3.UDPFrame</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t7">4.UDPSend</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t8">5.UDPReceive</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t9">6.ReminderTextAdapter（参考别人的，非原创）</a></li></ol></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t10">总结</a></li></ol></div>
            </div>
            </div>
        </div>
    </div>
</div>
</aside>
<script>
	$("a.flexible-btn").click(function(){
		$(this).parents('div.aside-box').removeClass('flexible-box');
		$(this).parents("p.text-center").remove();
	})
</script>
<script type="text/javascript" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/user-tooltip.js"></script>
<script type="text/javascript" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/user-medal.js"></script>    </div>
<div class="recommend-right  align-items-stretch clearfix" id="rightAside" data-type="recommend">
    <aside class="recommend-right_aside">
        <div id="recommend-right">
                        <div class="flex-column aside-box groupfile" id="groupfile" style="display: block; max-height: 362.5px;">
                <div class="groupfile-div" style="max-height: 362.5px;">
                <h3 class="aside-title">目录</h3>
                <div class="align-items-stretch group_item">
                    <div class="pos-box">
                        <div class="scroll-box">
                            <div class="toc-box"><ol><li class="active"><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t0">目录</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t1">效果展示</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t2">一、项目结构</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t3">二、完整代码</a></li><li class="sub-box"><ol><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t4">1.UDPClient</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t5">2.UDPServer</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t6">3.UDPFrame</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t7">4.UDPSend</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t8">5.UDPReceive</a></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t9">6.ReminderTextAdapter（参考别人的，非原创）</a></li></ol></li><li class=""><a href="https://blog.csdn.net/twj1248445531/article/details/111032255#t10">总结</a></li></ol></div>
                        </div>
                    </div>
                </div>
                </div>
            </div>
                <div id="recommendAdBox">
                    <div id="kp_box_479" data-pid="479"><iframe src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/saved_resource(5).html" frameborder="0" width="300px" height="600px" scrolling="no"></iframe><img class="pre-img-lasy" data-src="https://kunyu.csdn.net/1.png?p=479&amp;a=4313&amp;c=7542&amp;k=&amp;spm=1001.2101.3001.4834&amp;d=1&amp;t=3&amp;u=d793512e595a4e5fb10c92c7216d7cab" style="display: block;width: 0px;height: 0px;"></div>
                </div>
            <div class="aside-box kind_person d-flex flex-column">
                    <h3 class="aside-title">分类专栏</h3>
                    <div class="align-items-stretch kindof_item" id="kind_person_column">
                        <div class="aside-content">
                            <ul>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/twj1248445531/category_11051269.html" data-report-click="{&quot;mod&quot;:&quot;popu_537&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4137&quot;,&quot;strategy&quot;:&quot;pc付费专栏左侧入口&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/category_11051269.html&quot;,&quot;ab&quot;:&quot;new&quot;}">
                                        <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201014180756928.png" alt="" onerror="this.src=&#39;https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64&#39;">
                                        <span class="title oneline">
                                            <span class="text">课程笔记</span>
                                        </span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/twj1248445531/category_10913600.html" data-report-click="{&quot;mod&quot;:&quot;popu_537&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4137&quot;,&quot;strategy&quot;:&quot;pc付费专栏左侧入口&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/category_10913600.html&quot;,&quot;ab&quot;:&quot;new&quot;}">
                                        <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201014180756922.png" alt="" onerror="this.src=&#39;https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64&#39;">
                                        <span class="title oneline">
                                            <span class="text">项目异常</span>
                                        </span>
                                        <span class="count float-right">1篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/twj1248445531/category_10647469.html" data-report-click="{&quot;mod&quot;:&quot;popu_537&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4137&quot;,&quot;strategy&quot;:&quot;pc付费专栏左侧入口&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/category_10647469.html&quot;,&quot;ab&quot;:&quot;new&quot;}">
                                        <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201014180756928.png" alt="" onerror="this.src=&#39;https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64&#39;">
                                        <span class="title oneline">
                                            <span class="text">html学习</span>
                                        </span>
                                        <span class="count float-right">3篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/twj1248445531/category_10647981.html" data-report-click="{&quot;mod&quot;:&quot;popu_537&quot;,&quot;spm&quot;:&quot;1001.2101.3001.4137&quot;,&quot;strategy&quot;:&quot;pc付费专栏左侧入口&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/twj1248445531/category_10647981.html&quot;,&quot;ab&quot;:&quot;new&quot;}">
                                        <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/20201014180756928.png" alt="" onerror="this.src=&#39;https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64&#39;">
                                        <span class="title oneline">
                                            <span class="text">计算机网络小项目</span>
                                        </span>
                                        <span class="count float-right">3篇</span>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
            </div>
        </div>
    </aside>
</div>

</div><div class="notification" style="position: fixed; left:initial; right: 24px; top: 50px; bottom: initial; z-index: 99999;"></div><iframe class="bdSug_sd" style="display: none; position: absolute; border-width: 0px;" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/saved_resource(6).html"></iframe><div id="bdSug_1624496557860" class="bdSug_wpr" style="display: none;"></div>
<div class="mask-dark"></div>
<script>
    var articleId = 111032255;
    var commentscount = 4;
    var curentUrl = "https://blog.csdn.net/twj1248445531/article/details/111032255";
    var myUrl = "https://my.csdn.net/";
    var highlight = ["java","socket","计算机网络","udp","网络通信","Java","实现","简易","UDP","客户端","服务器端","通信","程序"];//高亮数组
    var isRecommendModule = true;
    var isBaiduPre = true;
    var baiduCount = 2;
    var share_card_url = "https://blog.csdn.net/twj1248445531/article/shareArticleCardPage?article_id=111032255"
	var articleType = 1;
    var baiduKey = "Java实现简易UDP客户端、服务器端通信程序";
    var userNewReport = false;
    var needInsertBaidu = true;
    var recommendRegularDomainArr = ["blog.csdn.net/.+/article/details/","download.csdn.net/download/","edu.csdn.net/course/detail/","ask.csdn.net/questions/","bbs.csdn.net/topics/","www.csdn.net/gather_.+/"]
    var codeStyle = "";
    var baiduSearchType = "title";
    var canRead = true;
    var blogMoveHomeArticle = false;
    var showPcWindowAd = false;
    var showSearchText = "";
    var linkPage = true;
    var articleSource = 1;
    var articleReport = '{"pid": "blog", "spm":"1001.2101"}';
    var isShowToQuestion = false;
</script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/sandalstrap.min.js"></script>
<div class="skin-boxshadow"></div>
<div style="display:none;">
	
</div>

<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/pc_wap_highlight-db1e81323a.min.js" type="text/javascript"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/pc_wap_common-906586e915.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/atom-one-light.css">
<script>
 // 全局声明
 if (window.csdn === undefined) {
      window.csdn = {};
    }
    window.csdn.sideToolbar = {
        options: {
            report:{
                isShow: true,
            },
            qr: {
                isShow: false,
            },
            guide: {
                isShow: true
            }
        }
    }
    $(function(){
        $(document).on('click',"a.option-box[data-type='report']",function() {
            window.csdn.userLogin.loadAjax(function(res){
                if(userNewReport){
                    showReportNew(false,articleTitles);
                }else{
                    showReport(false,articleTitles);
                }
            })
        });
    })
</script>
    <script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/baidu-search.js" type="text/javascript"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/user-ordercart.js" type="text/javascript"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/qrcode.js"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/common-d56939e7f0.min.js" type="text/javascript"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/detail-2dc339baaa.min.js" type="text/javascript"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/column-78261cfea6.min.js" type="text/javascript"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/side-toolbar.js" type="text/javascript"></script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/shop-window.js" type="text/javascript"></script>
<script>
    var shopUserName = username;
    ;$(function(){
        window.csdn.shop.show({
            userName: shopUserName,
            topEl: $("#csdn-shop-window-top"),
            bottomEl: $("#csdn-shop-window"),
            callBack: function(res){
                if(!res.top){
                    $("#blogColumnPayAdvert").css({"display":"block"})
                    $("#csdn-shop-window-top").css({"display":"none"})
                }
            }
        })
    })
</script>
<script src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/copyright.js" type="text/javascript"></script>
<script>
    $(".MathJax").remove();
    if ($('div.markdown_views pre.prettyprint code.hljs').length > 0) {
        $('div.markdown_views')[0].className = 'markdown_views';
    }
</script>
<script type="text/javascript" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/MathJax.js"></script>
<script type="text/x-mathjax-config;executed=true">
    MathJax.Hub.Config({
            "HTML-CSS": {
                    linebreaks: { automatic: true, width: "94%container" },
                    imageFont: null
            },
            tex2jax: {
                preview: "none",
                ignoreClass:"title-article"
            },
            mml2jax: {
                preview: 'none'
            }
    });
</script>
<script type="text/javascript" crossorigin="" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/login-box.js"></script>
<div id="pointDivs"><div class="point-outer point-pre"><div class="point-inner"></div></div><div class="point-outer point-pre"><div class="point-inner"></div></div><div class="point-outer point-pre"><div class="point-inner"></div></div><div class="point-outer point-pre"><div class="point-inner"></div></div><div class="point-outer point-pre"><div class="point-inner"></div></div></div><div id="st_mask" onclick="closeMask()" style="width: 100%; height: 100%; background: rgba(0, 0, 0, 0.4); position: fixed; left: 0px; top: 0px; display: none; z-index: 1;"></div><div id="st_confirmBox" style="width: 100%; position: fixed; left: 0px; top: 34%; text-align: center; display: none; z-index: 2;"><div id="st_confirm" style="width: 80%; margin: 0px auto; background: rgb(255, 255, 255); border-radius: 3px; overflow: hidden; padding-top: 20px; text-align: center;"><span id="st_confirm_text" style="background: rgb(255, 255, 255); overflow: hidden; padding: 15px 8px 30px; text-align: center; display: block;"></span><span class="st_confirm_btn cancel" style="background: rgb(255, 255, 255); color: rgb(141, 141, 141); padding: 8px; text-align: center; display: block; width: 50%; margin: 0px auto; float: left; box-sizing: border-box; border-top: 1px solid rgb(207, 207, 207); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"></span><span class="st_confirm_btn success" style="background: rgb(27, 121, 248); color: rgb(255, 255, 255); padding: 8px; text-align: center; display: block; width: 50%; margin: 0px auto; float: left; box-sizing: border-box; border-top: 1px solid rgb(27, 121, 248); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"></span><div style="clear: both; display: block;"></div></div></div><div id="st_alertBox" style="width: 100%; position: fixed; left: 0px; top: 34%; text-align: center; display: none; z-index: 2;"><div id="st_alert" style="width: 80%; margin: 0px auto; background: rgb(255, 255, 255); border-radius: 2px; overflow: hidden; padding-top: 20px; text-align: center;"><span id="st_alert_text" style="background: rgb(255, 255, 255); overflow: hidden; padding: 15px 8px 30px; text-align: center; display: block;"></span><span id="st_alert_btn" onclick="closeMask()" style="background: rgb(27, 121, 248); color: rgb(255, 255, 255); padding: 8px; text-align: center; display: block; width: 72%; margin: 0px auto 20px; border-radius: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"></span></div></div><div id="st_toastBox" style="width: 100%; position: fixed; left: 0px; bottom: 10%; text-align: center; display: none;"><span id="st_toastContent" style="color: rgb(255, 255, 255); background: rgba(0, 0, 0, 0.8); padding: 8px 24px; border-radius: 4px; max-width: 80%; display: inline-block; font-size: 16px;"></span></div> <div class="report-box">  <div class="pos-boxer">      <div class="pos-content">          <div class="box-title">              <p>举报</p>              <img class="icon btn-close" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/closeBlack.png">          </div>          <div class="box-header">              <div class="box-top"><span>选择你想要举报的内容（必选）</span></div>              <div class="box-botoom">                  <ul>                      <li data="1" type="nei">内容涉黄</li>                      <li data="2" type="nei">政治相关</li>                      <li data="3" type="nei">内容抄袭</li>                      <li data="4" type="nei">涉嫌广告</li>                      <li data="5" type="nei">内容侵权</li>                      <li data="6" type="nei">侮辱谩骂</li>                      <li data="8" type="nei">样式问题</li>                      <li data="7" type="nei">其他</li>                  </ul>              </div>          </div>          <div>          <div class="box-content">          </div>          <div class="box-content">          </div>                    <div class="box-content" style="display:none;">                  <div class="box-content-top">                          <span>原文链接（必填）</span>                      </div>                      <div class="box-content-bottom" style="padding-bottom: 16px;">                        <div class="box-input" style="height: 32px;line-height: 32px;">                        <input class="content-input" type="text" id="originalurl" name="originalurl" placeholder="请输入被侵权原文链接">                        </div>                      </div>          </div>          <div class="box-content">          </div>          <div class="box-content" style="display:none;">                  <div class="box-content-top">                          <span>请选择具体原因（必选）</span>                      </div>                  <div class="box-content-bottom">                          <ul>                              <li sub_type="1">包含不实信息</li>                              <li sub_type="2">涉及个人隐私</li>                          </ul>                      </div>          </div>          <div class="box-content" style="display:none;">                  <div class="box-content-top">                          <span>请选择具体原因（必选）</span>                      </div>                  <div class="box-content-bottom">                          <ul>                              <li sub_type="1">侮辱谩骂</li>                              <li sub_type="2">诽谤</li>                          </ul>                  </div>          </div>          <div class="box-content" style="display:none;">                <div class="box-content-top">                        <span>请选择具体原因（必选）</span>                    </div>                <div class="box-content-bottom">                        <ul>                            <li sub_type="1">搬家样式</li>                            <li sub_type="2">博文样式</li>                        </ul>                </div>          </div>          <div class="box-content" style="display:none;">          </div>          </div>            <div id="cllcont" style="display:none;">            <div class="box-content-top">              <span class="box-content-span">补充说明（选填）</span>            </div>                <div class="box-content-bottom">                  <div class="box-input">                    <textarea class="ipt ipt-textarea" style="padding:0;" name="description" placeholder="请详细描述您的举报内容"></textarea>                  </div>                </div>            </div>            </div>      <div class="pos-footer">          <p class="btn-close">取消</p>          <p class="box-active">确定</p>      </div>  </div></div><div class="imgViewDom disnone" style="display: none;"><img src="https://blog.csdn.net/twj1248445531/article/details/111032255" style="width: 1390px;"></div><style>.imgViewDom{display:none;position:fixed;top:0;left:0;height:100%;width:100%;z-index:99999999;background: rgba(255, 255, 255,0.8);overflow: auto;display:-webkit-box;-webkit-box-align:center;-webkit-box-pack:center;display:-moz-box;-moz-box-align:center;-moz-box-pack:center;display:-o-box;-o-box-align:center;-o-box-pack:center;display:-ms-box;-ms-box-align:center;-ms-box-pack:center; display:box;box-align:center;box-pack:center;}.imgViewDom img{cursor: zoom-out;}</style><svg aria-hidden="true" style="position: absolute; width: 0px; height: 0px; overflow: hidden;"><symbol id="sousuo" viewBox="0 0 1024 1024"><path d="M719.6779726 653.55865555l0.71080936 0.70145709 191.77828505 191.77828506c18.25658185 18.25658185 18.25658185 47.86273439 0 66.12399318-18.26593493 18.26125798-47.87208744 18.26125798-66.13334544 0l-191.77828505-191.77828506c-0.2338193-0.2338193-0.4676378-0.4676378-0.69678097-0.71081014-58.13206223 44.25257003-130.69075187 70.51978897-209.38952657 70.51978894C253.06424184 790.19776156 98.14049639 635.27869225 98.14049639 444.17380511S253.06424184 98.14049639 444.16912898 98.14049639c191.10488633 0 346.02863258 154.92374545 346.02863259 346.02863259 0 78.6987747-26.27189505 151.25746514-70.51978897 209.38952657z m-275.50884362 43.11621045c139.45428506 0 252.50573702-113.05145197 252.50573702-252.50573702s-113.05145197-252.50573702-252.50573702-252.50573783-252.50573702 113.05145197-252.50573783 252.50573783 113.05145197 252.50573702 252.50573783 252.50573702z"></path></symbol><symbol id="gonggong_csdnlogo_" viewBox="0 0 4096 1024"><path d="M1234.16069807 690.46341551c62.96962316 23.02318413 194.30703694 45.91141406 300.51598128 45.91141406 114.44114969 0 178.13952547-31.68724287 183.2407937-80.86454822 4.642424-44.8587714-42.21366937-50.93170978-171.44579784-81.53931916-178.57137886-43.77913792-292.49970264-111.55313011-281.32549604-219.86735976 12.9825927-125.75031047 181.27046257-220.78504823 439.49180199-220.78504822 125.88526465 0 247.93783044 8.87998544 311.17736197 29.60894839l-21.7006331 158.57116851c-41.05306337-14.27815288-198.1937175-34.11641822-304.48363435-34.11641822-107.7744129 0-163.56447339 33.90049151-167.42416309 71.06687432-4.85835069 47.04502922 51.14763648 49.23128703 191.14910897 86.50563321 189.58364043 48.09767188 272.47250144 115.81768239 261.6221849 220.81203906-12.71268432 123.51007099-164.13128096 228.53141851-466.48263918 228.53141851-125.85827383 0-234.33444849-22.96920244-294.09216204-45.93840492l19.730302-157.86940672zM3010.8325562 172.75216735c688.40130256-129.79893606 747.80813523 103.42888812 726.53935551 309.80082928l-40.08139323 381.78539207h-218.51781789l36.57258439-348.20879061c7.90831529-76.68096846 57.13960232-226.66905073-180.54170997-221.05495659-82.26807176 1.99732195-123.05122675 13.2794919-123.05122677 13.27949188s-7.15257186 92.65954408-15.81663059 161.13529804l-41.43093509 394.84895728h-214.3072473l42.53755943-389.15389062 28.09746151-302.43233073z m-869.48282929-18.05687008c49.12332368-5.34418577 124.58970448-10.76934404 228.45044598-10.76934405 173.38913812 0 313.57954648 30.17575597 400.38207891 93.63121421 77.94953781 59.16391512 129.82592689 154.95439631 115.4668015 293.74128117-13.25250106 129.15115596-80.405704 219.57046055-178.16651631 275.4954752-89.44763445 52.74009587-202.16137055 75.27744492-371.66382812 75.27744493-99.94707012 0-195.27870708-5.39816743-267.77609576-16.14052064L2141.37671774 154.69529727z m143.26736381 569.85754561c16.70732823 3.23890047 38.67786969 6.45081009 81.99816339 6.45081009 173.44311979 0 295.7386031-85.23706385 308.01943403-205.07638097 17.84094339-173.2271931-90.63523129-233.79463176-273.39018992-232.74198912-23.67096422 0-56.57279475 0-73.98188473 3.1849188l-42.6725136 428.15565036z" fill="#262626"></path><path d="M1109.8678928 870.30336371c-41.10704503 14.25116203-126.26313639 23.96786342-245.23874671 23.96786342-342.13585224 0-526.8071603-160.59548129-504.97157302-372.90540663C385.78470347 268.40769434 659.36382925 126.08500985 958.9081404 126.08500985c116.00661824 0 184.32042718 9.33882968 248.31570215 24.99351522l-20.5400271 170.42014604c-42.56455024-14.33213455-142.32268451-27.50366309-223.07926938-27.50366311-176.25016686 0-325.94134993 52.49717834-343.10752238 218.57179958-15.30380469 148.50358623 89.7715245 219.48948804 288.04621451 219.48948804 69.0155707 0 170.77102691-9.8786464 217.81605614-24.15679928l-16.49140154 162.40386737z" fill="#CA0C16"></path></symbol><symbol id="gonggong_csdnlogodanse_" viewBox="0 0 4096 1024"><path d="M1229.41995733 690.46341551c62.96962316 23.02318413 194.30703694 45.91141406 300.51598128 45.91141406 114.44114969 0 178.13952547-31.68724287 183.2407937-80.86454822 4.642424-44.8587714-42.21366937-50.93170978-171.44579784-81.53931916-178.57137886-43.77913792-292.49970264-111.55313011-281.32549604-219.86735976 12.9825927-125.75031047 181.27046257-220.78504823 439.49180199-220.78504822 125.88526465 0 247.93783044 8.87998544 311.17736197 29.60894839l-21.7006331 158.57116851c-41.05306337-14.27815288-198.1937175-34.11641822-304.48363435-34.11641822-107.7744129 0-163.56447339 33.90049151-167.42416309 71.06687432-4.85835069 47.04502922 51.14763648 49.23128703 191.14910897 86.50563321 189.58364043 48.09767188 272.47250144 115.81768239 261.6221849 220.81203906-12.71268432 123.51007099-164.13128096 228.53141851-466.48263918 228.53141851-125.85827383 0-234.33444849-22.96920244-294.09216204-45.93840492l19.730302-157.86940672zM3006.09181546 172.75216735c688.40130256-129.79893606 747.80813523 103.42888812 726.53935551 309.80082928l-40.08139323 381.78539207h-218.51781789l36.57258439-348.20879061c7.90831529-76.68096846 57.13960232-226.66905073-180.54170997-221.05495659-82.26807176 1.99732195-123.05122675 13.2794919-123.05122677 13.27949188s-7.15257186 92.65954408-15.81663059 161.13529804l-41.43093509 394.84895728h-214.3072473l42.53755943-389.15389062 28.09746151-302.43233073z m-869.48282929-18.05687008c49.12332368-5.34418577 124.58970448-10.76934404 228.45044598-10.76934405 173.38913812 0 313.57954648 30.17575597 400.38207891 93.63121421 77.94953781 59.16391512 129.82592689 154.95439631 115.4668015 293.74128117-13.25250106 129.15115596-80.405704 219.57046055-178.16651631 275.4954752-89.44763445 52.74009587-202.16137055 75.27744492-371.66382812 75.27744493-99.94707012 0-195.27870708-5.39816743-267.77609576-16.14052064L2136.635977 154.69529727z m143.26736381 569.85754561c16.70732823 3.23890047 38.67786969 6.45081009 81.99816339 6.45081009 173.44311979 0 295.7386031-85.23706385 308.01943403-205.07638097 17.84094339-173.2271931-90.63523129-233.79463176-273.39018992-232.74198912-23.67096422 0-56.57279475 0-73.98188473 3.1849188l-42.6725136 428.15565036z m-1174.74919792 145.75052083c-41.10704503 14.25116203-126.26313639 23.96786342-245.23874671 23.96786342-342.13585224 0-526.8071603-160.59548129-504.97157303-372.90540663C381.04396273 268.40769434 654.62308851 126.08500985 954.16739966 126.08500985c116.00661824 0 184.32042718 9.33882968 248.31570215 24.99351522l-20.5400271 170.42014604c-42.56455024-14.33213455-142.32268451-27.50366309-223.07926938-27.50366311-176.25016686 0-325.94134993 52.49717834-343.10752238 218.57179958-15.30380469 148.50358623 89.7715245 219.48948804 288.04621451 219.48948804 69.0155707 0 170.77102691-9.8786464 217.81605614-24.15679928l-16.49140154 162.40386737z"></path></symbol><symbol id="xieboke1" viewBox="0 0 1024 1024"><path d="M204.70021457 751.89799169h657.99199211a33.6932867 33.6932867 0 0 1 0 67.33536736H163.68452703a33.53966977 33.53966977 0 0 1-18.74125054-5.68382181c-18.63883902-9.4218307-18.17798882-29.44322156-15.20806401-39.17228615C199.0675982 570.27171976 309.41567149 409.58853908 435.38145354 290.12586836A243.22661203 243.22661203 0 0 1 536.97336934 234.20935065c138.10150976-33.79569759 228.3257813-29.95527721 318.60125827-28.52152054-17.15387692 20.48224105-36.20236071 41.6301547-57.29906892 62.93168529-3.1747472 3.22595323-164.67721739 19.91897936-187.97576692 47.05794871-23.29854894 27.13896932 129.60138005 7.37360691 125.19769798 11.11161576-21.6599699 18.33160576-44.90731339 36.4071831-69.94685287 53.8682939-4.50609297 3.1747472-149.52035944-0.35843931-174.61110436 27.85584737-25.19315641 28.16308124 101.89914903 18.12678338 96.0617103 21.40394206-67.43777825 37.63611797-125.96578207 64.62147036-212.70807253 93.8086635-57.65750823 19.4069231-121.8181284 133.13456658-146.5504346 179.06599187a435.75967738 435.75967738 0 0 0-23.04252112 49.10617311z" fill="#CA0C16"></path></symbol><symbol id="gitchat" viewBox="0 0 1024 1024"><path d="M892.08971773 729.08552746h-108.597062v-162.89559374H403.40293801v-108.59706198h488.68677972v271.49265572z m-651.58237345 54.298531V783.49265572h488.68678045v108.59706201H131.91028227V131.91028227h760.17943546v217.19412473h-108.597062V240.50734428H240.50734428v542.87671418z m542.98531145 0h108.597062v108.59706199h-108.597062v-108.59706199z" fill="#FF9100"></path></symbol><symbol id="toolbar-memberhead" viewBox="0 0 1303 1024"><path d="M1061.51168438 433.79527648A78.51879902 78.51879902 0 1 1 1129.35192643 472.74060007h-1.80593246l-48.05350474 403.97922198c-4.55409058 38.16013652-39.41643684 67.133573-80.79584389 67.13357302H319.35199503c-41.30088817 0-76.00619753-28.81639958-80.717325-66.97653526L189.01078861 472.74060007H187.12633728a78.51879902 78.51879902 0 1 1 67.76172401-38.86680556l193.31328323 119.81968805 158.13686148-336.06046024A78.5973179 78.5973179 0 0 1 658.23913228 80.14660493a78.51879902 78.51879902 0 0 1 51.58685077 137.721974l158.13686147 335.82490362 193.54883986-119.89820607z" fill="#FDD840"></path><path d="M1050.8331274 394.22180104a78.51879902 78.51879902 0 1 1 78.51879903 78.51879903h-1.80593246l-48.05350474 403.97922198c-4.55409058 38.16013652-39.41643684 67.133573-80.79584389 67.13357302H659.02432018C658.47468805 793.25433807 658.23913228 505.32590231 658.23913228 80.14660493a78.51879902 78.51879902 0 0 1 51.58685077 137.721974l158.13686147 335.82490362 193.54883986-119.89820607A78.51879902 78.51879902 0 0 1 1050.8331274 394.22180104z" fill="#FFBE00"></path></symbol><symbol id="toolbar-m-memberhead" viewBox="0 0 1303 1024"><path d="M1062.74839935 433.79527648A78.51879902 78.51879902 0 1 1 1130.58864141 472.74060007h-1.80593246l-48.05350474 403.97922198c-4.55409058 38.16013652-39.41643685 67.133573-80.79584389 67.13357302H320.58871c-41.30088817 0-76.00619753-28.81639958-80.71732499-66.97653526L190.24750358 472.74060007H188.36305226a78.51879902 78.51879902 0 1 1 67.761724-38.86680556l193.31328324 119.81968805 158.13686147-336.06046024A78.5973179 78.5973179 0 0 1 659.47584726 80.14660493a78.51879902 78.51879902 0 0 1 51.58685076 137.721974l158.13686148 335.82490362 193.54883985-119.89820607z" fill="#D6D6D6"></path><path d="M1052.06984238 394.22180104a78.51879902 78.51879902 0 1 1 78.51879903 78.51879903h-1.80593246l-48.05350474 403.97922198c-4.55409058 38.16013652-39.41643685 67.133573-80.79584389 67.13357302H660.26103515C659.71140302 793.25433807 659.47584726 505.32590231 659.47584726 80.14660493a78.51879902 78.51879902 0 0 1 51.58685076 137.721974l158.13686148 335.82490362 193.54883985-119.89820607A78.51879902 78.51879902 0 0 1 1052.06984238 394.22180104z" fill="#C1C1C1"></path></symbol><symbol id="csdnc-upload" viewBox="0 0 1024 1024"><path d="M216.37466416 723.16095396v84.46438188h591.25067168v-84.46438188c0-23.32483876 18.90735218-42.23219094 42.23219093-42.23219021s42.23219094 18.90735218 42.23219096 42.23219021v84.46438188c0 46.64967827-37.81470362 84.46438188-84.46438189 84.46438189H216.37466416c-46.64967827 0-84.46438188-37.81470362-84.46438189-84.4643819v-84.46438187c0-23.32483876 18.90735218-42.23219094 42.23219096-42.23219021s42.23219094 18.90735218 42.23219094 42.23219021zM469.76780906 275.55040991L246.55378774 499.53305726a42.30820888 42.30820888 0 0 1-59.99082735 0c-16.56346508-16.62259056-16.56346508-43.57095155 0-60.19354139L480.51167818 144.38144832A42.21952103 42.21952103 0 0 1 512 131.93984464a42.20262858 42.20262858 0 0 1 31.48409853 12.44160369l293.95294108 294.95806754c16.56346508 16.62259056 16.56346508 43.57095155 0 60.19354139a42.30820888 42.30820888 0 0 1-59.99082735 0L554.23219094 275.55040991V680.92876375c0 23.32483876-18.90735218 42.23219094-42.23219094 42.23219021s-42.23219094-18.90735218-42.23219094-42.23219021V275.55040991z"></path></symbol></svg><div id="BAIDU_DUP_fp_wrapper" style="position: absolute; left: -1px; bottom: -1px; z-index: 0; width: 0px; height: 0px; overflow: hidden; visibility: hidden; display: none;"><iframe id="BAIDU_DUP_fp_iframe" src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/o.html" style="width: 0px; height: 0px; visibility: hidden; display: none;"></iframe></div><div>
  <div class="csdn-side-toolbar " style="left: 1391px;">
    
    <a class="option-box" data-type="guide">
      <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/guide.png" alt="" srcset="">
      <span class="show-txt">新手<br>引导</span>
    </a>
    
    
    
    
    <a class="option-box" data-type="cs">
      <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/kefu.png" alt="" srcset="">
      <span class="show-txt">客服</span>
    </a>
    
    
    
    <a class="option-box" data-type="report">
      <span class="show-txt" style="display:flex;opacity:100;">举报</span>
    </a>
    
    
    <a class="option-box go-top-hide" data-type="gotop">
      <img src="./(35条消息) Java实现简易UDP客户端、服务器端通信程序_twj1248445531的博客-CSDN博客_files/fanhuidingbucopy.png" alt="" srcset="">
      <span class="show-txt">返回<br>顶部</span>
    </a>
    
  </div>
  </div><textarea id="hljs-copy-el" style="position: absolute; left: -9999px; top: 2330px;">package udpCommunication;

import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

public class ReminderTextAdapter extends FocusAdapter {
    //JTextField提示文字通用方法
    JTextField textField;
    String reminderString;

    //初始化
    public ReminderTextAdapter(JTextField textField, String reminderString) {
        this.textField = textField;
        this.reminderString = reminderString;
    }

    //焦点获得
    @Override
    public void focusGained(FocusEvent e) {
        String tempString = textField.getText();
        //String tempString = this.getText();
        if (tempString.equals(reminderString)) {
            textField.setText("");
            textField.setForeground(Color.BLACK);
        }
    }

    //焦点失去
    @Override
    public void focusLost(FocusEvent e) {
        String tempString = textField.getText();
        if (tempString.equals("")) {
            textField.setForeground(Color.GRAY);
            textField.setText(reminderString);
        }
    }

}
</textarea></body></html>